Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
Closed this issue ยท 3 comments
Hello! Nice try. Happy to see this lib built for optimizing render with Proxies.
Assuming you would like to get some feedback, here's one case.
I think the api is fine and it's just an implementation matter.
https://codesandbox.io/s/statery-clicker-game-forked-l67qu?file=/src/App.tsx Click "Toggle".
Yes, this is currently a caveat that I'm not happy about, and as you probably already know, is caused by property accesses to the proxy object invoking React hooks.
The current workaround is to immediately destructure the proxy into the variables you need before using them in expressions (like I'm doing in the example sandbox and the examples in the README), but of course there's an element of surprise to this that I'm not fond of, and do want to fix. I'm just still thinking about how to do it nicely.
Fixed in the upcoming 0.4.0 release.