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
(initialState: S | (() => S)): [S, Dispatch>]; (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts) useState returns a tuple of a S value, and a Dispatch Function to update the state – jgoday Mar 17 '19 at 14:18