react avoid spreading non-dom props across component 1

react avoid spreading non-dom props across component

function MyDiv(props) {

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

  if (props.layout === 'horizontal') {
    return 
} else { return
} }

Here is what the above code is Doing:
1. We’re creating a new component called MyDiv.
2. We’re passing all the props that are passed to MyDiv to the div that we’re returning.
3. We’re deleting the layout prop from the props that we’re passing to the div.
4. We’re checking if the layout prop is horizontal or vertical.
5. If the layout prop is horizontal, we’re returning a div with the horizontal style.
6. If the layout prop is vertical, we’re returning a div with the vertical style.

Now, let’s use our new component:

Similar Posts