Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refs as effect conditions #17

Open
gnordhielm opened this issue Apr 16, 2019 · 1 comment · May be fixed by #29
Open

Refs as effect conditions #17

gnordhielm opened this issue Apr 16, 2019 · 1 comment · May be fixed by #29

Comments

@gnordhielm
Copy link

I don't believe this code will work as expected:

[ref.current]
.

A change in a ref will not case a re-render, so there's no guarantee that this effect will be called. I'd suggest refactoring it to accept an empty array - it'll work the same.

@osdiab
Copy link

osdiab commented Mar 4, 2020

I agree - I've confirmed in my project it doesn't work properly, because if the ref changes it won't trigger useEffect to refresh. You're supposed to use useCallback to make a callback ref like the React docs recommend.

Currently trying to figure out how I can use that approach with this library, though the TypeScript typings assert that it needs a RefObject as the parameter, which this callback approach does not produce - I'm thinking I need to make a fake RefObject that actually is just the DOM element I retrieve and store in state from the useCallback() ref, so that the library can use it

@osdiab osdiab linked a pull request Mar 4, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants