Awesome, I have tried a similar one for updating state if the component is mounted in typescript-react,
code looks like:
const useStateMounted = <T,>(initialValue: T): [T, React.Dispatch<React.SetStateAction<T>>] => { const isMounted = useMounted(); const [state, setState] = useState(initialValue); const newSetState = (value: any) => { if (isMounted.current) { return setState(value); } }; return [state, newSetState]; };
Problems?
eslint-plugin
useEffect
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Awesome, I have tried a similar one for updating state if the component is mounted in typescript-react,
code looks like:
Problems?
eslint-plugin
and asking for addition on the dependency array ofuseEffect
.