How to define type of setUserData, extracted from useMoralis()?

I don’t know how to dismiss this issue of below :

Argument of type ‘string’ is not assignable to parameter of type ‘SetUserData’.ts(2345)

import MoralisType from "moralis";
import { useState } from "react";
import CustomContainer from "../CustomContainer";
import { FormControl, FormLabel, Text, Input, Button } from "@chakra-ui/react";
import { useMoralis } from "react-moralis";

type ProfileProps = {
  user: MoralisType.User | null;
  account: string | null;
};
// export default
function Profile({ user, account }: ProfileProps) {
  const [input, setInput] = useState("");
  const { setUserData, isUserUpdating } = useMoralis();

  console.log("user ======>", user);
  return (
    <CustomContainer>
      <Text>
        <b> 😆 &nbsp; Username:</b>
        {user && user.get("username")}
      </Text>
      <Text>
        <b> 💰 &nbsp; Wallet:</b> {account}
      </Text>
      <form
        onSubmit={(e) => {
          e.preventDefault();
          // input.trim != ""
          if (input.trim.length > 0) {
            setUserData({
              username: input,
            }).then(() => setUserData(""));
          }
        }}
      >
        <FormControl>
          <FormLabel htmlFor="username">Set a new username</FormLabel>
          <Input
            id="username"
            type="text"
            placeholder="ex. Jesse"
            value={input}
            onChange={(e) => setInput(e.target.value)}
          ></Input>
          <Button
            type="submit"
            mt="6"
            disabled={isUserUpdating}
            colorScheme="purple"
          >
            ✅&nbsp;Change Username
          </Button>
        </FormControl>
      </form>
    </CustomContainer>
  );
}
export { Profile };

Did you try it with ({""})

since the user is an object you have to specify what are you changing.

setUserData({ username: ""})
1 Like

Yes, it worked, thanks a lot.

1 Like