[SOLVED] Multiple useMoralisCloudFunction in one React component?

Is it possible to call two (or more) cloud functions inside the same React component?

const { fetch, data, error, isLoading } = useMoralisCloudFunction("getLastName", {
     firstname: 'Jake',
});

const { fetch, data, error, isLoading } = useMoralisCloudFunction("getFirstName", {
     lastname: 'Smith',
});

This will give me an error, because fetch, data, error, isLoading are already declared. Is there any other way to call useMoralisCloudFunction that would allow me to do it multiple times in one component?

if you give them different names second time then it would work? like {fetch2, data2, error2, isLoading2}?

Sadly this won’t work, already tried

then maybe using Moralis.Cloud.run directly?

I’ve decided to split my component into 2 which is probably a better practice anyway. Thanks for the help tho! :slight_smile:

1 Like

Hey you can use two different cloudfunction hooks .
just rename it like this:

fetch: fetch1, data: data1 

And so on

2 Likes

That’s super helpful, thanks!

1 Like

Hey Loco can you provide an example please - not sure what you mean? Thanks :facepunch: :pray:

All good, I got it now!