Is it possible to set the default comparison function to shallow?
See original GitHub issueI recently updated to Zustand 3.6.5. The changed order of .subscribe
and the need to use subscribeWithSelector
came as a bit of a surprise but once I worked everything out it’s worth it for the improved types.
However, I now have to import shallow from 'zustand/shallow'
all over my app. So far there’s nowhere that I don’t want to use shallow comparison. Is there any way to set the default comparison function on the store itself? Or if not, could this feature be added?
Issue Analytics
- State:
- Created 2 years ago
- Comments:26 (14 by maintainers)
Top Results From Across the Web
How does shallow compare work in react - Stack Overflow
Shallow compare works by checking if two values are equal in case of primitive types like string, numbers and in ...
Read more >Shallow Compare - React
shallowCompare performs a shallow equality check on the current props and nextProps objects as well as the current state and nextState objects. It...
Read more >Shallow Comparison vs Deep Comparison in Javascript
You most likely heard terms shallow comparison and deep comparison. ... Now we can simply add default Javascript comparison at the end of...
Read more >Shallow Comparison vs Deep Comparison in Javascript
Learn the difference between shallow comparison, deep comparison and javascript comparison by building this functions with me from scratch.
Read more >Default comparisons (since C++20) - cppreference.com
3) Declare the defaulted comparison function as a non-member function. Arguments are passed by value. The three-way comparison function (whether ...
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
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
For anyone looking to use the wrapper approach and are wondering what to replace the deprecated
StateSelector
with, this works:Oh… I thought it’s very obvious. We could add docs about wrapping with custom hooks. This should be very powerful, not only for this use case.
It increases bundle size. For enhancing features like this, middleware is the way already provided, or a wrapper like that.