I have this simple example that's giving me grief:
useEffect(() => {
axios.get(...).then(...).catch(...)
}, [props.foo])
warning: can't perform a react state update on an unmounted component
Done some research and this one is more understandable. TypeScript seems not to like that approach as useEffect should return a void.
useEffect(() => {
let isSubscribed = true
axios.get(...).then(...).catch(...)
return () => (isSubscribed = false)
}, [props.foo])
TypeScript:
/**
* Accepts a function that contains imperative, possibly effectful code.
*
* @param effect Imperative function that can return a cleanup function
* @param deps If present, effect will only activate if the values in the list change.
*
* @version 16.8.0
* @see https://reactjs.org/docs/hooks-reference.html#useeffect
*/
function useEffect(effect: EffectCallback, deps?: DependencyList): void;
How to implement an isSubscribed in my useEffect with TS?
Thanks.