Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Type 'unknown' is not assignable to type '(prevState: number | undefined) => number | undefined'

$
0
0

I am using material ui's select component to save the selected value in a variable:

const [ratio, setRatio] = useState<number>();...const handleChangeRatio = (e: React.ChangeEvent<{ name?: string | undefined; value: unknown; }>) => {    //const value = typeof e.target.value === "number" ? e.target.value : "";    setRatio(e.target.value);};...<Select        labelId="demo-simple-select-filled-label"        id="demo-simple-select-filled"        value={splittingMethod}        onChange={(e)=>handleChangeRatio(e)}><MenuItem value={0}>            0</MenuItem><MenuItem value={0.1}>0.1</MenuItem><MenuItem value={0.2}>0.2</MenuItem></Select>

However, I get this error while setting the state inside the handleChange function, how can I fix this?

Argument of type 'unknown' is not assignable to parameter of type 'SetStateAction<number | undefined>'.  Type 'unknown' is not assignable to type '(prevState: number | undefined) => number | undefined'.

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>