[SOLVED] Prevent cloud function to be called when react component mounts

So Iโ€™m having that issue with React where all the cloud function calls I define in my page are being called when the page is mounted. This is obviously a problem since I only want those functions to be called when I call them :slight_smile:
This is maybe due to the new react strict mode that automatically remount the components, not sure about that, but i donโ€™t think so, I guess this just makes that the functions are called twice ><

Here is how I declare my functions :


  const {
    fetch: fixDbFetch,
    data: fixDbData,
    error: fixDbError,
  } = useMoralisCloudFunction('fixDb', { autoFetch: false });

the react moralis doc say this about autofetch :

If you want to disable the automatic fetching, you can also manually fetch. You need to provide autoFetch: false as option in the 4th argument. In that case it will ignore the dependencies and will only fetch if you manually call fetch()

But i guess this is only to prevent fetch on dependency update. not on mount apparently.

Is there any way to declare that within a function and not inside the component ?

Thanks

For autoFetch to work there (since youโ€™re not passing in params), you need an empty object.

const {
    fetch: fixDbFetch,
    data: fixDbData,
    error: fixDbError,
  } = useMoralisCloudFunction('fixDb', {}, { autoFetch: false });
1 Like

awesome, thank you :slight_smile: