Selectors not firing after store update #3039
-
I've got a method in my store called removeProduct:
I also have a
When I execute
Am I misunderstanding how to use "selectors" in zustand? What am I doing wrong here and how do I fix this? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I believe it's because you are lacking hook functionality here. You should be using zustand like this: export function getProductsByGroup(
group: ProductItemGroup,
onlyAvailableInStore = false
) {
return useProductsStore((state) => {
const products = state.products;
// ...bunch of code here
});
} Also side note, when you are getting data from state like this (and expecting a rerender), it's called a hook and usually people prefix hooks with |
Beta Was this translation helpful? Give feedback.
-
@reintroducing |
Beta Was this translation helpful? Give feedback.
I believe it's because you are lacking hook functionality here. You should be using zustand like this:
Also side note, when you are getting data from state like this (and expecting a rerender), it's called a hook and usually people prefix hooks with
use
. SogetProductsByGroup
would look better asuseProductsByGroup
.