Accessibility · Senior · Question 20 of 75

A React handler sets state to show a panel, then calls ref.current.focus(). Why does it fail?

Show the answer

Correct answer: The panel isn't rendered yet when focus is called

Explanation

State updates are batched and rendered after the handler. Use an effect keyed to the state or flushSync when the element must exist right away.

Further reading

Problem with a question

Accessibility · Senior · question 20

Test yourself

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

Take this quiz