Back

Assigning a user type object to a react state (typescript)

  • 0
  • Accounts
  • Web
larkx
27 Feb, 2024, 21:24

Hello, ESLint is flagging my code for assigning the user object (returned from account.get()) to a react state which is initially defined with the value "null"

const [user, setUser] = useState(null)

How do I fix this error?

TL;DR
- Developer asking for help importing types from Appwrite - Recommending checking the documentation for the correct types - Question about typing useState with `Models.User<Models.Preferences>` - ESLint error flagged when assigning user object to react state initially set as "null" - Suggested solution: Specify the type in useState like `useState<Models.User<Models.Preferences>>(null)`
Kenny
27 Feb, 2024, 21:35

should your useState be typed? useState<Models.User<Models.Preferences>>();

larkx
27 Feb, 2024, 21:45

Sure but where do I find the correct types for Appwrite stuff

larkx
27 Feb, 2024, 21:45

Like how do I import the types they use

angol
27 Feb, 2024, 21:48

Might be like this: import { type Models } from 'appwrite'; @larkx

Kenny
27 Feb, 2024, 21:51

You import Models from appwrite

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more