r/learnreactjs • u/parrita710 • May 04 '22
Question Passing array as prop to a component
Hi. Noob in Reactjs from Java here.
I get a Uncaught TypeError: props.val is undefined when I try to give a value from a array to a component and not sure what I'm doing wrong. The components in question:
Row.js
function Row(props) {
return (
<div className="row">
<Dice val={props.val[0]} />
...
<Dice val={props.val[5]} />
</div>
);
}
export default Row;
App.js
return (
<div className="App">
<div className="board">
<Row val={array[0]} />
<Row val={array[1]} />
...
<Row val={array[10]} />
</div>
</div>"array" It's multidimensional and I want to each "Row" have one of the arrays which passes each value to a "Dice".
5
Upvotes
View all comments
Show parent comment
1
u/parrita710 May 04 '22
In another coment I tried to pass an array with [1, 2, 3, 4, 5] that he recomended to try but It throws the same error. If I don't try to select a value from the array It compiles and I can see the array in the component but as soon as I try to select a value from it I recived the undefined.The react dev tools extension shows the tree of components correctly like: