Skip to content

Commit ab0e238

Browse files
committed
Use onQueryRemoval in react-query
1 parent 0e727ab commit ab0e238

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

packages/normy-react-query/src/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ export const createNormalizedQueryClient = (
77
) => {
88
const normalizer = createNormalizer(normalizerConfig);
99

10+
const queryCache = new QueryCache({
11+
onSuccess: (data, query) => {
12+
normalizer.onQuerySuccess(query.queryKey.join(','), data);
13+
},
14+
});
15+
16+
queryCache.subscribe(event => {
17+
if (event.type === 'removed') {
18+
normalizer.onQueryRemoval(event.query.queryKey.join(','));
19+
}
20+
});
21+
1022
const queryClient = new QueryClient({
1123
...reactQueryConfig,
12-
queryCache: new QueryCache({
13-
onSuccess: (data, query) => {
14-
normalizer.onQuerySuccess(query.queryKey.join(','), data);
15-
},
16-
}),
24+
queryCache,
1725
mutationCache: new MutationCache({
1826
onSuccess: data => {
1927
normalizer.onMutationSuccess(data, queriesToUpdate => {

0 commit comments

Comments
 (0)