@lido-sdk/react
Version:
This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li
24 lines (21 loc) • 658 B
JavaScript
import { useRef, useState, useEffect, useCallback } from 'react';
const useMountedState = (initialState) => {
const mountedRef = useRef(false);
const [state, setState] = useState(initialState);
useEffect(() => {
mountedRef.current = true;
return () => {
mountedRef.current = false;
};
}, []);
useEffect(() => {
setState(initialState);
}, [initialState]);
const setMountedState = useCallback((...args) => {
if (!mountedRef.current)
return;
setState(...args);
}, []);
return [state, setMountedState];
};
export { useMountedState };