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

store function in ref to avoid having to mention it as a dependency #18

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

bacalj
Copy link
Collaborator

@bacalj bacalj commented Aug 8, 2024

This stores a ref to getUniqueLocationsInCodapData which needs to be called from a useEffect (and thus the function was supposed to be put in the dependencies). This was causing re-renders and breaking the interaction with CODAP via the API - I think because it was trying to reinitialize each time the component re-rendered.

@bacalj bacalj requested a review from pjanik August 8, 2024 19:24
Copy link
Member

@pjanik pjanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Given the nature of the problem, I think another solution could be to wrap all these functions in useCallback inside useCodapData. That way, the client wouldn't need to worry about using refs. But I'm speculating.

@pjanik pjanik merged commit a12e81a into main Aug 8, 2024
5 checks passed
@pjanik pjanik deleted the location-function-ref branch August 8, 2024 19:30
@kswenson
Copy link
Member

kswenson commented Aug 8, 2024

Looks good 👍

Given the nature of the problem, I think another solution could be to wrap all these functions in useCallback inside useCodapData. That way, the client wouldn't need to worry about using refs. But I'm speculating.

I agree. A quick glance suggests that some of the functions may not require access to local data, i.e. they could be global functions.

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 this pull request may close these issues.

3 participants