Replies: 5 comments 7 replies
-
Here's what I ended up doing to solve this, but it feels like I'm missing a "front door" here. My function checks to see if a username being chosen exists already. This solution leverages react-query only really for it's cache:
|
Beta Was this translation helpful? Give feedback.
-
Same! - I like how with const [updateUser] = useMutation(UserService.updateUser)
//down in my component code
<input
onChange=((e) => {
const bio = e.target.value;
updateUser({bio})
})
/> I wish I could do something like this with const [getBooks] = useQuery(UserService.updateUser)
//down in my component code
<input
onChange=((e) => {
const title = e.target.value;
getbooks({title}, {
onSuccess: (books) => console.log(books)
})
})
/>
|
Beta Was this translation helpful? Give feedback.
-
You can always do useQuery and set it to enabled: false, and then work with the |
Beta Was this translation helpful? Give feedback.
-
This is how i end up with, where useSalesOrdersQuery is a regular query fn
|
Beta Was this translation helpful? Give feedback.
-
If it's still relevant, something similar to the following worked for my use-case. const [userInput, setUserInput] = React.useState('');
const { refetch, isFetching } = useQuery({
queryKey: ['key', userInput],
queryFn: () => getSomeUserData(userInput),
enabled: false
});
const handleSomeStateUpdate = input => {
// ...
setUserInput(input);
};
const handleBtnClick = () => {
refetch();
};
// ... Some notes
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have case where I'd like to use a query as a function in my component, instead of specifying the parameter in useQuery.
If I have an API to call with a parameter, where I specify the array key,
I'd like to instead get an async function that I could call to perform the query, and have the array key be generated for me.
The reason is I have validation logic in a useEffect hook that needs to call an API, and takes in an async function for the validation, and I would like to have the API results get cached.
Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions