Reputation: 5150
When I save an array to a state and then read it back again I get the error Type 'string[]' is not assignable to type 'never[]' what is this all about?
I made a code sandbox here: https://codesandbox.io/s/affectionate-pasteur-kj5h0 where the code runs but shows the error in red underlines
Upvotes: 5
Views: 6695
Reputation: 7495
If you strongly type the generic param for useState
you're all good
const [state, setState] = useState<{ array1: string[] }>({ array1: [] });
Upvotes: 14