【发布时间】:2020-07-05 22:17:23
【问题描述】:
为什么该代码工作不正常?我更改了 profileId 并没有发生任何事情,useLazyQuery 仍然返回旧数据。
const [profile, setProfile] = useState<Profile>(null);
const [getProfile, { loading, error, data }] = useLazyQuery<Data<'profile', Profile>, { id: string }>(PROFILE, {
ssr: false,
});
useEffect(() => {
getProfile({
variables: { id: profileId },
});
}, [getProfile, profileId]);
useEffect(() => {
if (!loading && !error && data) {
setProfile(data.profile);
}
}, [setProfile, data, loading, error]);
我正在使用:
"@apollo/react-hooks": "^3.1.3",
"apollo-client": "^2.6.8",
【问题讨论】:
标签: reactjs react-hooks react-apollo