Want to set initial state with using ES6 class in React? You may also want to check out this post about the difference between when to use a constructor and when to use getInitialState.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import React, { Component } from 'react'; export default class App extends Component { constructor(props) { super(props); this.state = { text: 'Hello World' }; } render() { return ( <div> {this.state.text} </div> ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.