Answers for "react avoid spreading non-dom props across component"

0

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()} />
  }
}
Posted by: Guest on September-21-2021

Code answers related to "react avoid spreading non-dom props across component"

Code answers related to "Javascript"

Browse Popular Code Answers by Language