Skip to content

[Basic] Hooks: useState type #403

Closed
Closed
@priscilaandreani

Description

@priscilaandreani

What cheatsheet is this about? (if applicable)

Basic cheatsheet

What's your issue or idea?
Idea

instead of:

const [user, setUser] = React.useState<IUser | null>(null);

// later...
setUser(newUser);

you can use:

const [user, setUser] = React.useState<IUser>({} as IUser);

// later...
setUser(newUser);

(of course if IUser is an object)

its always great to start the state using its initial format

Metadata

Metadata

Assignees

Labels

BASICBasic Cheatsheet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions