Auto-refresh select function when Zustand state changes
Hello! I need help with an issue I'm facing when using TanStack Query with Zustand.
I'm fetching data with TanStack Query and then filtering it based on a state managed by Zustand. My selector function directly accesses the Zustand store internally:
1. The
2. When the user changes the filter state by clicking a filter button, TanStack Query doesn't detect this change and doesn't re-run the
3. As a result, the UI doesn't update to show the filtered data when the filter state changes.
Current Situation
I'm fetching data with TanStack Query and then filtering it based on a state managed by Zustand. My selector function directly accesses the Zustand store internally:
Problem Description
1. The
filteredTodosByStatus function internally uses useFilterStore.getState().status to get the current filter state.2. When the user changes the filter state by clicking a filter button, TanStack Query doesn't detect this change and doesn't re-run the
select function.3. As a result, the UI doesn't update to show the filtered data when the filter state changes.