All jobs / Frontend / web developer / React

Frontend / web developer interview question · 0–1 years

What does useState return, and why must you call the setter instead of assigning?

The strongest answer

A pair: the current value and a setter; React re-renders only when the setter is called, so assigning to the variable changes nothing on screen

Why it works

Right. The setter is how React learns something changed.

What a good answer covers

Answers that fall short

Who gets asked this

More React questions