基于响应数据时如何使用SWR重新获取

how to useSWR refetch when based response data

如何根据响应数据重新获取?

就我而言

const key = `/analyses/${anSeq}`;
const response = useSWR<IGetAnalysis>(key, fetcher);

if (typeof response.data?.simularityJson.analyzes === "undefined") {
    setTimeout(() => response.mutate(), 1000
    // I want to get data every 1s;
}

return response;

总结

const {data, mutate} = useSWR(key, fetcher);

if (typeof data?.someData === "undefined") {
    setTimeout(()=>mutate(), 1000);
};

refreshInterval

解决了
const [condition, setCondition] = useState<boolean>(false);

const key = `/analyses/${anSeq}`;
const response = useSWR<IGetAnalysis>(key, fetcher, {
   refreshInterval: conditon ? 0 : 5000, // not refresh is 0
});

useEffect(() => {
    if (response.data?.someData) {
        setIsAnalysed(true);
    }
}, [response.data?.someData]);