处理这个问题的唯一方法是将handleOnClick
中的date
存储到useState
变量中,然后在useEffect
中重新获取它吗?有什么方法可以只调用handleOnClick
中的Reaction Query吗?
const { data, refetch } = useQuery(
[day],
() => getTimes(day), // i cannot instantiate day here as it needs to be passed in by handleOnClick parameter
{
enabled: false,
}
);
export const getTimes = async (day: string) => {
const response = await fetch(`/api/calendar?byDay=true&day=${day}`);
return await response.json();
};
const handleOnClick = async (date: string) => {
// date param is getting returned here by a 3rd party component
const times = await getTimes(date); // what i normally would do
// refetch; // what i would like to do but can't
}