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

Using ref instead of mutable in store record #43

Open
MargaretKrutikova opened this issue Mar 2, 2019 · 3 comments
Open

Using ref instead of mutable in store record #43

MargaretKrutikova opened this issue Mar 2, 2019 · 3 comments

Comments

@MargaretKrutikova
Copy link
Collaborator

According to reason-react docs instance variables should be stored in state and be marked with ref instead of mutable to prepare for concurrent react.

I am unsure whether this makes any difference for a global state management solution like reductive, but would be nice to have a better insight into this from someone who has a better understanding of the internals of reductive and reason-react. If it does make a difference, the fix is rather simple but nice to have to be ready for the future changes.

Would appreciate any opinions/thoughts on this :)

@bloodyowl
Copy link

the ref type is roughly:

type ref('a) = {
  mutable contents: 'a
};

so that wouldn't change much conceptually 😊

@MargaretKrutikova
Copy link
Collaborator Author

hm... yes, that makes sense. However, the docs I linked show an example in reasonml playground that demonstrates the difference when reading from state from a closure. Then it seems to work incorrectly if using mutable since the data might get stale by the time it is accessed. So it seems like there might be a risk of having the same problem in reductive..

Please correct me if I am misunderstanding something!

@rickyvetter
Copy link
Owner

For the function api I think preferring useRef where possible makes sense. For the old API yes, you must use a ref inside of state instead of a mutable field. Is there a scenario in the function api where useRef doesn't make sense?

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

No branches or pull requests

3 participants