-
Notifications
You must be signed in to change notification settings - Fork 6
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
Better to just use Proxy state warning when using useSnapShot #26
Comments
@barelyhuman Can take a look? |
Yes sir! 🫡 To get better context, you are using snapshots to add into the render tree correct? or are you using snapshots in a hook or a function etc , I'll need a little more code snippet or repro to see what's actually causing the rule to fire |
Assuming we are on the same page, both these tests seem to be passing and have no errors Also, there was a bug in the middle which could cause an unwanted warning , which you can confirm by installing this If that doesn't fix, please try to give a small snippet |
Thanks, that should be enough to find the issue |
@tavolafourcade |
@tavolafourcade |
Just installed the eslint plugin, and think I might be running into something similar (not sure, but didn’t want to open a new ticket). Changing line 60 in @barelyhuman Am I doing something wrong here? |
I think this is related to #32 You might wanna try the PR specific build as mentioned here: #33 (comment) Let me know if that fixes it for you. Also , simplest way to use valtio
if a useCallback or useEffect is reading the snapshot just make sure to add it in the dependency array so you don’t have undefined behaviour eg: function Comp(){
const snap = useSnapshot(prxyState)
return <>{snap.count}</>
} func Comp(){
const snap = useSnapshot(prxyState)
useEffect(()=>{
console.log(snap);
},[snap])
} but if you are writing to the snapshot, it won't work as intended and you should write to the prxyState directly |
This was my current understanding - I’ve built a decently large project with Valtio before and had no issue using in ways like this. Just installed the plugin and found the error confusing. Looks like removing the export from the function declaration fixed it. IE
throws the error, but const MyFunc = () => ()
export { MyFunc } Doesn’t. if I change from an arrow function to a named function: export function MyFunc() {} it also fixes the error. Thanks for the quick response! Glad to know i’m not using valtio incorrectly 😄 |
yeah, so the next release should handle this, till then you can use the build from the PR if it’s blocking any CI/ git hooks. A previous change we made to make sure the snapshot isn’t being written to inside hooks is what’s caused this issue. |
Hello,
I'm facing an issue with the latest version of eslint-plugin-valtio (0.4.4). The problem is that I'm using useSnapShot to re render the variable from the Store.
When I replace this implementation and call the variable directly from the Store the warning get fixed but the variable doesn't render anymore...
I tried changing the declaration of arrow function for the keyword function without success (#22).
const { isEditedMInformation } = useSnapshot(memberInformationStore)
vs
memberInformationStore.isEditedMInformation
I wasn't able to find any solution to my issue. Can somebody give me a guidance about it? Thanks!
The text was updated successfully, but these errors were encountered: