Skip to content

Feature Request: Global didUpdate() #10900

@ccorcos

Description

@ccorcos

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions