Forbid lazy state return.
See original GitHub issueEven though the following “kind” of action is frowned upon, we could go one step further and ignore state updates (as well as re-renders).
myAction(state) {
state.prop = 1
return state
}
The change requires we simply check if the appState === newState
and return early.
Issue Analytics
- State:
- Created 6 years ago
- Comments:34 (27 by maintainers)
Top Results From Across the Web
Is it possible to prevent `useLazyQuery` queries from being re ...
When using useLazyQuery , you can set nextFetchPolicy to "standby" . This will prevent the query from firing again after the first fetch....
Read more >Find N+1 problems instantly by disabling lazy loading
Learn about the strict lazy loading setting that allows you to disable it entirely for non-production environments.
Read more >How To Handle Async Data Loading, Lazy Loading, and Code ...
In this step, you made your app update state only when a component is mounted. You updated the useEffect Hook to track if...
Read more >Relationship Loading Techniques
Lazy loading refers to objects are returned from a query without the related objects loaded at first. When the given collection or reference...
Read more >Lazy loading React components - LogRocket Blog
React.lazy() takes as its argument a function that must return a promise by calling import() to load the component. The returned promise ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jamen Yep, we are on sync now. 😉
And my opinion about that was expressed here.
tl;dr: This is a do-it-at-your-own-risk kind of “feature”; I won’t force you to do things in a particular way (although you should), but I am not going to go “out of my way” to let you do it either (unless there’s some trivial change that allows it).
Oh… I get it now! Mutating state in props is unsafe because of the shallow merge. While each action gets a new state instance, the properties containing objects will not be fresh instances.
Ok, so the unsafeness of mutating deep state properties is a completely separate issue to what’s being proposed here (because it would continue being unsafe, even if we did implement this).
…even so, I’m still not sure I like this proposal because it will be difficult to debug. I’ve written that sort of inappopriate actions in many places. This sort of “silent fail” would make refactoring harder. So if we eventually do take it in, it should be after we have a dev-build which can log warnings. Or failing that, make production builds throw errors terminating and providing stack traces.
@okwolf Thanks for giving that example! I was actually aware of the object-spread operator to use in this case, but for me personally, I don’t consider it a solution as it is only a stage-3 proposal and not yet standard ecmascriot.