-
Hello everyone! I'm fetching data from react-query for my list and then I pass it to my Store:export const useFilterCollectionsStore = <S>(
queryData: GetCollectionListItem[],
selector: StateSelector<UseFilterCollectionsStore, S>
) =>
create<UseFilterCollectionsStore>((set) => ({
collections: [],
filter: (matchFilter) =>
set((state) => {
console.log(state, queryData); // actually gets udpated, but not in list component
return {
collections: queryData.filter(({ name }) => textMatchFilter(name, matchFilter)),
};
}),
}))(selector); List component:const filteredCollections = useFilterCollectionsStore(
collections && collections.length > 0 ? collections : [],
(state) => state.collections
);
useEffect(() => {
// Is getting updated only, when data from react-query is changing
// But is not getting updated, when I call filter() from useFilterCollectionsStore
console.log(filteredCollections);
}, [filteredCollections]); |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Apr 22, 2021
Replies: 1 comment 5 replies
-
Please try to |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
smashboy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please try to
create
outside render, not inside the custom hook.