You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use useSnapshot(nestedState.proxy) when nestedState is a regular object, you get a false positive of Mutating a proxy object itself. this might not be expected as it's not reactive. eslint(valtio/state-snapshot-rule).
Having just nestedState.proxy.settings = {}; is not enough for whatever reason. It has to be assigned to a second proxy object. nestedState.proxy.settings = state2.settings;
import{proxy,useSnapshot}from"valtio";import{useEffect}from"react";constnestedState={proxy: proxy({settings: nullasnull|Record<string, unknown>})};conststate2=proxy({settings: nullasnull|Record<string, unknown>});exportfunctionComponent(){// Badconstsnap=useSnapshot(nestedState.proxy);// Good// const proxy = nestedState.proxy;// const snap = useSnapshot(proxy);// This is where the linting error occursnestedState.proxy.settings=state2.settings;// This is a more realistic example.// useEffect(() => {// nestedState.proxy.settings = state2.settings;// }, []);return<div>{JSON.stringify(snap.settings)}</div>;}
The text was updated successfully, but these errors were encountered:
I'll check the code but from what i've worked with till now, I'm sure that the proxy identifier is not detectable in this case.
To be fair, it's not right or wrong but what's implemented right now and since it's obvious that it could be more than just a single identifier the same should be implemented.
Not a small change though so might take a bit long.
For now you can just alias and move forward with it
const proxy = nestedState
2nd problem is that because of how the initial implementation works, we don't know anymore if nestedState is the proxy or nestedState.proxy is the proxy so the linter can't really work with the 2nd level state change and will give an error.
The functionality will work as is, it's just that the linter plugin has no idea of the identifier.
and if you **use the alias to modify, the linter should not complain about it
When you use
useSnapshot(nestedState.proxy)
whennestedState
is a regular object, you get a false positive ofMutating a proxy object itself. this might not be expected as it's not reactive. eslint(valtio/state-snapshot-rule)
.Having just
nestedState.proxy.settings = {};
is not enough for whatever reason. It has to be assigned to a second proxy object.nestedState.proxy.settings = state2.settings;
The text was updated successfully, but these errors were encountered: