Replies: 1 comment
-
import useSWR from 'swr';
export const getTask = (taskId) => {
const { data, error, mutate } = useSWR(
'queryAsyncResultByTaskId',
() => queryAsyncResultByTaskId(taskId),
{
refreshInterval: (latestData) =>
latestData?.data?.status !== 'SUCCESS' ? 1000 : 0,
}
);
useEffect(() => {
if (data?.data?.status === 'SUCCESS') {
console.log('entry', data);
setErrorCategoryMap(data?.data);
mutate(data, { revalidate: false });
}
}, [data, mutate]);
return { data, error, mutate };
}; |
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
-
export const getTask = (taskId) => { const { data, error, mutate } = useSwr('queryAsyncResultByTaskId', () => queryAsyncResultByTaskId(taskId), { refreshInterval: 1000}); useEffect(() => { if (data?.data?.status === 'SUCCESS') { console.log('entry', data); setErrorCategoryMap(data?.data) mutate( data, { revalidate, } ); } }, [data, mutate]); return { data, error, mutate }; };
Beta Was this translation helpful? Give feedback.
All reactions