-
Hi! Thank you for this great library. I've read your documentation over and over again while refactoring my code. However, some things are still unclear to me regarding this sentence:
it logically doesn't trigger re-render (as expected #transient).
Now, React linting will tell me to remove machineConfig because it's not used. If I try to use machineConfig inside useMemo, then your linting will warn me to use proxy state instead (state-snapshot-rule). So, whichever I choose, I get a warning. Is this intended, should I just ignore it or am I using it the wrong way? I do NOT get the React warning when I use useEffect() for some reason...but I still get the one regarding state-snapshot-rule. I read the part on React.memo(), though. Does this apply to useMemo() as well?
I hope this is clear to you, thank you so much in advance!! Alex |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Oh, yes! You are right.
Hm, good point.
There's a pitfall with this usage. If you touch
Yeah, that's a valid suggestion. useEffect(() => {
// ...
const unsub = subscribe(state, () => { ... })
// ...
return unsub
}, [..., /* no proxy state nor snap here */]) For I'd want more feedback on these. |
Beta Was this translation helpful? Give feedback.
Oh, yes! You are right.
Hm, good point.
[obj.a, obj.b]
in deps is not preferred in React in general, because it can be changed? (I guess eslint rules warn this, but maybe it's improved?)But in valtio
snap
is a frozen object, so there would be no pitfalls.There's a pitfall with this usage. If you touch
machineConfig.foo
in the same render function. It will not work as expected.Yeah, that's a valid suggestion.
But, not sure what to suggest for certain.
The recommended pattern for
useEffect
is:us…