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/[deleted] May 04 '22
Ok, then your calls look fine to me. My only other thoughts would be that either you're not iterating your array properly or the array is not actually set up. I would probably test out some basic cases, like when only array[0][0] is used and console log at each step. Without knowing your data, you could be just working with a bad array or something. When you log around you may see a problem to fix.