how to initialize state in react code example
Example: initialize state react
class App extends React.Component {
constructor(props) {
// Required step: always call the parent class' constructor
super(props);
// Set the state directly. Use props if necessary.
this.state = {
loggedIn: false,
currentState: "not-panic",
// Note: think carefully before initializing
// state based on props!
someInitialValue: this.props.initialValue
}
}
render() {
// whatever you like
}
}