React-moralis noob question - multiple cloud functions same component

Using react-moralis, how can we call more than one cloud function in the same component with one cloud function needing a parameter?

Do you want to do concurrent calls or one after the other?

Can you give a more elaborate explanation of this?

You can just call the hook multiple times and it will be ok. You have to rename the returned value though like:

const { data: scoreData, error: scoreError, isLoading: scoreIsLoading } = useMoralisCloudFunction("topScores");
const { data: playerData, error: playerError, isLoading: playerIsLoading } = useMoralisCloudFunction("players");

or

const topScoreCloudQuery = useMoralisCloudFunction("topScores");
const playerCloudQuery = useMoralisCloudFunction("players");

// Use topScoreCloudQuery.data / topScoreCloudQuery.error etc. or playerCloudQuery.data / playerCloudQuery.error etc. anywhere

I think you could use data from the first cloud function as parameter in the second cloud function, if that is what you are trying to do. For example

const topScoreCloudQuery = useMoralisCloudFunction("topScores");
const playerCloudQuery = useMoralisCloudFunction("players", {minScore: topScoreCloudQuery.data});

Or something along those lines.
I hope this helps :slight_smile:

2 Likes

That is exactly what I was looking for thank you!

1 Like