Skip to content

Selectors not firing after store update #3039

Answered by mooalot
reintroducing asked this question in Q&A
Discussion options

You must be logged in to vote

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 use. So getProductsByGroup would look better as useProductsByGroup.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@reintroducing
Comment options

Answer selected by reintroducing
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants