I am new in react and I have an issue that I didn't find any solution for after search.
When I store the array of html tags in variable I get minified React error #31
var k = [1,2,3];
var x = k.map(e=><li>{e}</li>);
var e = (
<div>
<ul>
{1 && {x}}
<ul>
</div>
);
var divTag = document.getElementById("k");
ReactDOM.render(e,divTag)
But when I write this I get no errors.
var k = [1,2,3];
var x = k.map(e=><li>{e}</li>);
var e = (
<div>
<ul>
{1 && k.map(e=><li>{e}</li>)}
<ul>
</div>
);
var divTag = document.getElementById("k");
ReactDOM.render(e,divTag)
You need to remove the curly braces around the x
variable {1 && {x}} -> {1 && x}
You are defining a new object containing the key x
instead of just passing the array to react
The solution
Replace {1 && {x}}
with {1 && x}
Because you've wrapped x
into curly braces, you've got the rendering error (you wanted to provide the array).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.