Source:  Twitter logo

Hello I'm having this error:

Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'.

this is a part of my code:

const[ idPadre, setIdPadre ] = useState<number>(0);

       onChange={ (e) => setIdPadre( ) }
       value={ idPadre }
<option value="">Select...</option>
       { => {
                            return <option key={}
                                    value={ }

so, I'm adding data from file json and I want that select an item and value get id.

The error is pretty descriptive. You cannot pass parameter of type string into the useState hook which expects number.

You're calling the setIdPadre hook with the variable, which is a string.

What you can do instead is convert the value into a number:

{ (e) => setIdPadre( parseInt( ) }
5 users liked answer #0dislike answer #05
Val profile pic

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).