Direct link: https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
The example says
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
function handleClick() {
forceUpdate();
}
But this makes typescript report an error. (The typescript types are provided by the react team itself right? otherwise I might need to file a bug with the team maintaining the types)
Possible fixes:
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
function handleClick() {
forceUpdate("something"); //I added an argument here
}
will pass the type checker
const [ignored, forceUpdate] = useState(0); //useState instead of useReducer
function handleClick() {
forceUpdate(x => x + 1); //calculate function
}
is also ok (and a bit nicer IMHO)
Direct link: https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
The example says
But this makes typescript report an error. (The typescript types are provided by the react team itself right? otherwise I might need to file a bug with the team maintaining the types)
Possible fixes:
will pass the type checker
is also ok (and a bit nicer IMHO)