Elegant way to create a reusable, type-safe queryFn? #3642
Unanswered
agusterodin
asked this question in
Q&A
Replies: 1 comment
-
In my opinion, this is not the place where you should control whether or not there's a text search. I'd rather use the "skip" option in the query or the skipToken. Doc link Eg. useGetTargetListSearchResultsQuery(searchText, {
skip: !searchText.length
});
// or
import { skipToken } from '@reduxjs/toolkit/query/react';
useGetTargetListSearchResultsQuery(searchText || skipToken); With this, you can use query instead of queryFn and get the typing you've defined. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I had to set up a queryFn as shown below to get an autocomplete searchbox to behave the way I wanted. Is there a type-safe way to turn it into a reusable function so it can be used in other areas of my app?
Beta Was this translation helpful? Give feedback.
All reactions