Reputation: 8702
Is it possible to receive ALL props passed in a child component without explicitly specifying them one by one? Eg:
const ParentComponent = () => {
return <ChildComponent
prop1={"foo"}
prop2={"bar"}
prop3={"baz"}
/>
}
const ChildComponent = (props) => {
return <input /*GIMME ALL PROPS HERE*/ />
}
Upvotes: 0
Views: 60
Reputation: 10837
Use the spread operator for this -
const ChildComponent = (props) => {
return <input {...props} />
}
This gets automatically interpreted as -
const ChildComponent = (props) => {
return <input prop1={"foo"}
prop2={"bar"}
prop3={"baz"} />
}
Upvotes: 3