3

Why that code is working improperly ? I change profileId and nothing happened, useLazyQuery is still returns the old data.

    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]);

I am using:

    "@apollo/react-hooks": "^3.1.3",
    "apollo-client": "^2.6.8",

1 Answer 1

2

You need to set fetchPolicy to:

fetchPolicy: 'network-only'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.