I have this simple component, initialPlayers
props is passed to App
component.
import React from 'react';
import ReactDOM from 'react-dom';
var PLAYERS = [
{
name: "xyz",
score: 123
}
];
// App component
class App extends React.Component {
constructor() {
super();
}
componentDidMount() {
this.state = {
players: this.props.initialPlayers
}
}
render() {
return(
<div>
<Header players={this.state.players} />
</div>
);
}
}
// Render component
ReactDOM.render(<App initialPlayers={ PLAYERS }/>,
document.getElementById('root'));
Have this error in console, and not able to pass value to Header
component as {this.state.players}
. Any idea?.
Uncaught TypeError: Cannot read property 'players' of null
at App.render (bundle.js:14379)
at bundle.js:20173
at measureLifeCyclePerf (bundle.js:19452)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (bundle.js:20172)
at ReactCompositeComponentWrapper._renderValidatedComponent (bundle.js:20199)
at ReactCompositeComponentWrapper.performInitialMount (bundle.js:19739)
at ReactCompositeComponentWrapper.mountComponent (bundle.js:19635)
at Object.mountComponent (bundle.js:4667)
at ReactCompositeComponentWrapper.performInitialMount (bundle.js:19748)
at ReactCompositeComponentWrapper.mountComponent (bundle.js:19635)