Last updated
Was this helpful?
Last updated
Was this helpful?
There are two kinds of components in React - function components and class components. Function components and hooks are the modern way of writing React but there are still a lot of legacy codebases using class components so it's still a must-know for any React developer.
Class components must inherit from Component
and have a render method that returns jsx
We can access props through this.props
Initialise the state object either using a constructor
or the simpler field declaration syntax
Access state through this.state
Update state through this.setState
(same immutable update rules apply)
Define event handlers as a method and use an arrow function to bind this
to the instance