React state comparison: class vs function

remarkablemark
Mar 20, 2021

YouTube:

CodeSandbox:

Class

Rendering initial state:

Updating state:

Class state property must be an object since setState takes an object of state variables to update.

Function

Rendering initial state:

Updating state:

There can be multiple useState hooks in a function.

The initial state passed to useState doesn’t have to be an object:

Resources

--

--