How is option value string even after accepting a ``value={prop}`` of a number type?
Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'
Meanwhile I type
setPerPage: React.Dispatch<React.SetStateAction<number>>
because the only thing i want it to accept must only be numbers
How is option value string even after accepting a value={prop}
of a number type?3 Replies
you're using react to generate HTML, which after it's been generated is just plain HTML, and values in HTML are always strings when you fetch them back. The value doesn't remember how it was set, it just gets turned into a string that, along with the rest of the giant string that represents all your HTML, gets parsed by the browser
effectively, your React code is generating HTML which is handed to the browser, and then when you ask for some of it back elsewhere by checking a value, the HTML only understands strings, so it can only give you a string back
so can i still convert the string to number if i want to?
or thats never going to happen
you can, yeah. You can just use
parseInt
like you would on any other input, how the value was set originally doesn't matter