How Can I Pass Multiple Values In A Single Prop In React?
Is there any way where I can pass in multiple values in a single prop? Right now how it works is I have one component and it takes in lots of values like this:
Solution 1:
You can pass an array or an object:
// e.g
<MyComponentvalueAB={[100,90]}
valueC={{a:100, b:90}} />
And in MyComponent you will get valueAB prop as array, hence you can do something like:
props.valueAB[0]// 100
Or for objet : props.valueC.a
is also 100 .
Solution 2:
I think you can do add them as a one object as you did {{100, 90}} or one array {[100,90]}
and you can easily extract them from the array like this:
let myCompValueABFirst = props.valueAB[0];
let myCompValueABSecond = props.valueAB[1];
Post a Comment for "How Can I Pass Multiple Values In A Single Prop In React?"