Can you use useOne and have it call a callback when the data changes
I saw onLiveUpdate but i don't have a live provider so I'm not sure if that's going to do what I want.
Basically I want to have a function called when the data from the hook is available so I can update a separate store with information derrived from the value. I saw "queryOptions.onSuccess" which could do what I want but it seems to be deprecated.
I'm trying to avoid 'useEffect'.
3 Replies
Hi @Plornt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the provided extracts, the
useOne
hook in Refine does not directly support a callback function that is triggered when the data changes. The onLiveEvent
property, which does provide a callback function, requires a LiveProvider
to work, which you mentioned you do not have.
However, you mentioned queryOptions.onSuccess
, which could potentially serve your purpose. This option is part of the queryOptions
that can be passed to the useOne
hook. Unfortunately, the provided extracts do not mention if this option is deprecated or not.
Here is an example of how you might use queryOptions.onSuccess
:
If queryOptions.onSuccess
is indeed deprecated, you might need to resort to using useEffect
or find another solution. I would recommend checking the official Refine documentation (https://refine.dev/docs) for the most up-to-date information.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@383377580524306465> kapa.ai is still learning and improving, please let us know how it did by reacting below
noble-gold•12mo ago
Hey @Plornt we use react-query@v4 at the moment, so you should be able to use
queryOptions.onSuccess
.