NextJs / Basics / Usage of type object
Usage of type object
-
1. Files
1. A type of object would look something like this:
type UserData = { name: string, age: number, status: boolean } 2. Using the type object to initialize a new state:
Optional fieldstype UserData = { name: string, age: number, status: boolean } // New State const [user, setUser]=useState ({name: 'Johnn Doe', age: 12, status: true}) type UserData = { name?: string, age?: number, status?: boolean } // New State const [user, setUser]=useState ({age: 12})