React · Senior · Question 14 of 75

What is useEffectEvent for?

Explanation

Example: a chat connection effect depends on roomId, and on connection you need to show a notification using the current theme. Adding theme to dependencies would reconnect the chat on theme change. const onConnected = useEffectEvent(() => notify(theme)) always sees the fresh theme but isn't reactive.

Further reading

Problem with a question

React · Senior · question 14

Test yourself

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

Take this quiz