What does it mean to derive state, and why is it better than syncing it with an effect?

React state and events · Experienced

Model answer

Derived values can be calculated from existing state or props during render, such as filteredItems from items and a search string, or fullName from first and last name. Storing them in separate state and updating them in useEffect adds extra renders and bugs when they get out of sync.

Calculate during render, and use useMemo only if the calculation is truly expensive.

Learn this topic

React useState Explained: Make Your Page React to Change in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions