use refetch result in next line

When I use refetch functiom from useCustom, the data variable is not updated inmediatly, what can I do so I can use the data in the next line of the refetch?
kapa.ai
kapa.ai68d ago
Hi @Jaoc1811. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The refetch function from useCustom hook in Refine is asynchronous, meaning it doesn't immediately update the data. It sends a new request to the server and waits for the response. Therefore, you can't use the updated data in the next line right after calling refetch. However, you can use the data variable inside a useEffect hook to perform actions whenever the data changes. Here's an example:
import { useEffect } from 'react';
import { useCustom } from '@refinedev/core';

// ...

const { data, refetch } = useCustom(/* your parameters */);

useEffect(() => {
if (data) {
// Perform your actions with the updated data here
}
}, [data]);

// Call refetch somewhere in your code
refetch();
import { useEffect } from 'react';
import { useCustom } from '@refinedev/core';

// ...

const { data, refetch } = useCustom(/* your parameters */);

useEffect(() => {
if (data) {
// Perform your actions with the updated data here
}
}, [data]);

// Call refetch somewhere in your code
refetch();
In this example, the useEffect hook will run every time the data changes, allowing you to perform actions with the updated data. For more information, you can check the useCustom documentation (https://refine.dev/docs/data/hooks/use-custom) on the Refine website. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai68d ago
<@110864105035808768> kapa.ai is still learning and improving, please let us know how it did by reacting below