-
Notifications
You must be signed in to change notification settings - Fork 49.4k
Closed
Description
Currently, its not easy to write global logic that executes after React has re-rendered. The componentDidUpdate
lifecycle method works great when your logic is isolated to a component, but I've found myself more and more recently wanting a global didUpdate
hook baked into React.
A simple example where this is useful is if you want an isolated function (perhaps a keyboard shortcut) that creates an element on the screen and then focuses it.
const createNewTodo = async () => {
const id = createTodo()
await React.didUpdate()
focusTodoItem(id)
}
At Notion, we've written custom logic for doing this, but it makes upgrading with React more difficult and unstable. I think this would be useful for others too, particularly those who use Redux and are building complicated UI interactions.
pspeter3