1class App extends React.Component {
2 constructor(props) {
3 // Required step: always call the parent class' constructor
4 super(props);
5
6 // Set the state directly. Use props if necessary.
7 this.state = {
8 loggedIn: false,
9 currentState: "not-panic",
10
11 // Note: think carefully before initializing
12 // state based on props!
13 someInitialValue: this.props.initialValue
14 }
15 }
16
17 render() {
18 // whatever you like
19 }
20}
21
1//initial state
2const [state, setState] = useState(0)
3//change state
4setState(1)
5//change state with prev state value
6setState((prevState) => {prevState + 2}) // 3