Reputation: 193
I have a local json object that I can pass to a React class when just calling it by name, but when I try and pass a property of the object, I get an error. Is it possible to use javascript dot notation when using React?
var Player = {
{
"name": "Money",
"value": 0
},
{
"name": "Market Share",
"value": 0
}
}
};
React.render(
<StatsPane stats={Player} ticker={Settings.eventTickRate} />,
document.getElementById('stats-pane')
);
var Player = {
"stats": {
0: {
"name": "Money",
"value": 0
},
1: {
"name": "Market Share",
"value": 0
}
}
};
React.render(
<StatsPane stats={Player.stats} ticker={Settings.eventTickRate} />,
document.getElementById('stats-pane')
);
Upvotes: 1
Views: 2279
Reputation: 817238
Is it possible to use javascript dot notation when using React?
The error is not in the code you posted. It has nothing to do with React or JSX.
As you can see, the error message points to
this.setState({stats: {Player.stats}});
// ^
{Player.stats}
is simply not valid a JavaScript object literal. Here is a simpler example that reproduces the issue:
> var foo = {bar.baz};
Uncaught SyntaxError: Unexpected token .
I believe you want
this.setState({stats: Player.stats});
or something similar.
Upvotes: 7