Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react avoid spreading non-dom props across component

function MyDiv(props) {

  const divProps = Object.assign({}, props);
  delete divProps.layout;

  if (props.layout === 'horizontal') {
    return <div {...divProps} style={getHorizontalStyle()} />
  } else {
    return <div {...divProps} style={getVerticalStyle()} />
  }
}
Source by reactjs.org #
 
PREVIOUS NEXT
Tagged: #react #avoid #spreading #props #component
ADD COMMENT
Topic
Name
3+8 =