Sole
Sole

Reputation: 3340

Type for object in React/Typescript

What is the type for a object in React/Typescript for example:

const [value, setValue] = React.useState<any>({});

if I need to define it as an object what type would I put in, instead of <any>

Upvotes: 0

Views: 6694

Answers (1)

SlothOverlord
SlothOverlord

Reputation: 2037

interface MyObject {
  [k: string]: any;
}

const [value, setValue] = React.useState<MyObject>({});

[k: string]: any; means that property must be a string, and it's value are any.

Upvotes: 3

Related Questions