setUserData() not recognized in react component

Hi Guys,

I am trying to use the setUserData() function in my react component to setup some metadata for the user logged in.
The code can not compile and I am getting the following error:

setUserData' is not defined  no-undef

I thought I imported moralis correctly but may be missing something, could you please advise, see below the code.
Note that the user login (crypto) is taken care of in another component.
Also note that I imported moralis at the top of the page with:

import { useMoralis } from 'react-moralis'

The fields orgName, orgLocation, adminFirstName, adminLastName refer to columns fields for user metadata that I have added manually as columns on the moralis server dashboard.

const { isAuthenticated, user} = useMoralis()

const addOrganizationAdminMoralis = (organizationName, organizationLocation, adminFirstName, adminLastName) => {
    if (isAuthenticated) {
      console.log('The user is authenticated')
        orgName: organizationName,
        orgLocation: organizationLocation,
        adminFirstName: adminFirstName,
        adminLastName: adminLastName,

Could you please advise why is the code not compiling and why the setUserData function is not recognized?

Thank you

1 Like

Hi @Tristan3000,

You cannot find the function because it’s neither imported or initialised in the component.

You have to first initialise the function from our useMoralis hook.

This way –
const { isAuthenticated, user, setUserData } = useMoralis();

Perhaps, we missed the initialisation in the documentation. Is that way you missed it as well?

Hope this helps. :slight_smile:

1 Like

Thank you for the prompt response, that worked :slight_smile:
Indeed this instruction is missing from the Github docs:

1 Like