Skip to content

Refs are stuck with their initial values. Ref mutations are not reflected in the hook return value #528

@DavidKrpt

Description

@DavidKrpt

Here's a minimal reproduction repo made with CRA
https://github.com/DavidKrpt/ref-issue-in-react-singleton-hook

Initially tested with react 16 and react-singleton-hook 3.4.0.
But for a quick minimal app I used CRA, and it came with react 19.
There's a peer dependency issue with react 19, so npm install needs to be done with --force
But it works the same way regardless. Just install with force, start, open the page at localhost:3000 and check the console.

Obviously, the example code makes little practical sense, it's just there to illustrate the issue.
Initially I was trying to have a shared mutable object available at different parts of the component tree, but couldn't make it work with react-singleton-hook. So I ended up using context. I think plain old global variables would also do the trick, but I was trying to do things the react way

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions