I have the following:
interface FormValues {
max: number
}
Then, I do:
let [formValues, setFormValues] = useState({max: 5})
When I do console.log(formValues.max)
I get a typescript error. How do I tell the destructuring call that formValues
is of type FormValues
and that setFormValues
is a function?
This is not a duplicate of this:
Destructuring assignment in Typescript
or fo this:
Destructuring assignment via TypeScript in React
Neither of those answer the question
you can set the type of the state
export interface IValueType { max: number }
let [formValues, setFormValues] = useState<IValueType>({max: 5})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.