How to call fetch with useMoralisCloudFunction new params?

Hi,

The fetch function the results from useMoralisCloudFunction must have a way to pass params at the time when fetch() is invoked rather than when the hook is invoked.

//I need to be able to do this 
  const { data, 
    error, 
    fetch, 
    isFetching, 
    isLoading,
} = useMoralisCloudFunction("updateGame", undefined, { autoFetch: false });
//Somewhere else in the app
fetch(gameUpdate) //This doesn't pass anything

I figured out a workaround by refactoring the code.

Basically, insteading of calling the fetch() directly, set the params as state from a useState hook and put the fetch() in a useEffect with the state as the dependency. Then whenever I want to call the cloud function, set the state of the params.

I still think it’s a bit strange the fetch() doesn’t take params.

2 Likes