React · Middle · Question 14 of 75

What's the right way to get fullName from firstName and lastName stored in state?

Explanation

Values that can be computed from props and state shouldn't be stored in state. The "state + syncing effect" combo causes an extra render with a stale value and a risk of desync. If the computation is expensive, wrap it in useMemo.

Further reading

Problem with a question

React · Middle · question 14

Test yourself

Take the React · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz