Answer the question
In order to leave comments, you need to log in
How to properly store and display multiple elements from state?
I'm trying to make a state with many<UserRow/>
//через loop множество UserRow загружаю
that.setState( {user_row: that.state.user_row+<UserRow/>} );
//Выводит так [object Object][object Object][object Object]
that.setState( {user_row: <UserRow/>} );
Answer the question
In order to leave comments, you need to log in
"+" is a string addition or concatenation operator, so each of the objects is converted to a string. If toString()
the object method is not defined, the string will be "[objectObject]".
Instead, create an array, fill it in a loop, and paste it as is. You will need to add a unique value for the "key" property to each element, otherwise React may swear. See the React documentation on Dynamic Children .
render() {
var i, rows = [];
for(i=0;i<N;i++) { rows.push( <UserRow key={ i } /> ); }
// ..
return (
<div>
{ rows }
</div>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question