Pass multiple props to an react component
React is a much popular framework these days. Today I show you how you can pass multiple props to and component, so you don't need unnecessary code.
I really like the JSX template language. It is like HTML meets Javascript, so it is easy to understand, but also very powerful.
But how can you pass a collection of properties to an react component. Your first idea may be to pass them one by one like this.
const testComponent = ({ children, name other }) => {
return <OtherComp name={name} other={other}>{children}</OtherComp>;
}
But you can also write less code and archive the same thing.
const testComponent = ({children, ...props}) => {
return <OtherComp {...props}>{children}</OtherComp>;
}
Header Photo by Ferenc Almasi on Unsplash