Home:ALL Converter>Typescript error on react useState hook when updating typescript version

Typescript error on react useState hook when updating typescript version

Ask Time:2020-09-17T12:47:51         Author:u53r

Json Formatter

I developed a react typescript application with react 16.9 and typescript 3.5.2. It uses react state hooks like

const [hValue, setHValue] = useState();

type of the hValue is IValue

So the setHValue has return type React.Dispatch<any>

Then I updated the typescript version to 3.9.7 and it gives compilation errors and it seems that now the return type of setHValue has changed to React.Dispatch<React.SetStateAction<undefined>>

Why is that? and how to resolve this issue?

Author:u53r,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/63931439/typescript-error-on-react-usestate-hook-when-updating-typescript-version
yy