Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

useLazyQuery returns old data

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",
like image 572
Stanislav Avatar asked Jul 03 '26 01:07

Stanislav


1 Answers

You need to set fetchPolicy to:

fetchPolicy: 'network-only'
like image 125
Bora Sumer Avatar answered Jul 05 '26 14:07

Bora Sumer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!