Practice
If a component's behaviour depends on the state of the component, it can be called a stateful component. These stateful components are always class components and have state that is initialised in the
class App extends Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
render() {
// ...
}
}
React 16.8 update: hooks let you use state and other React features without writing classes.
The equivalent functional component
import React, {useState} from 'react';
const App = (props) => {
const [count, setCount] = useState(0);
return (
// JSX
)
}
Comments