I have a component that uses useQuery
to fetch and display a list of Cities.
<>Cities.js
const { data, isInitialLoading, isError, refetch } = useQuery(
["cities"],
() => axios.get("http://localhost/cities"),
{
staleTime: 10000,
}
);
// Display loading indicator
if (isInitialLoading) {
return <div>Loading...</div>;
}
return (
// Display cities
{data.map(city => {
return <p> City: {city.name} </p>
})}
// Call refetch method once clicked
<button onClick={() => refetch()}> call refetch</button>
)
上面显示的<><>但<><>>>>>>> > > > > > > > > 一旦被点击,即应为<>refetch数据。 我的问题是,当<代码>refetch时。 这种方法如上所示,可人工称为react-query
查询cache
,然后回到。 如果存在,或<代码>refetch
>always向特定终点提出新的品牌要求? 我已经将<代码>staletime设定为10秒,因此,refetch
将卡列结果退回10秒钟,然后在数据被考虑之后,再发出新的电话,以至<代码>