React performance in one tweet: Declare state as local as possible


React performance in one tweet:

Declare state as local as possible.

If state is only used by part of the JSX:
1. Split the component
2. Move the state down to the new component

Result? State changes run less code.
And there are non-performance benefits.

Local state is:

1. Less code
2. Less bug prone
3. Easier to understand
4. Avoids needlessly passing props

View original on X