reductive
reductive copied to clipboard
Using ref instead of mutable in store record
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 :)
the ref
type is roughly:
type ref('a) = {
mutable contents: 'a
};
so that wouldn't change much conceptually 😊
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!
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?