1234567891011121314151617181920212223242526 |
- import * as React from 'functional-mini/compat';
- export function useSafeState(defaultValue) {
- var destroyRef = React.useRef(false);
- var _a = React.useState(defaultValue), value = _a[0], setValue = _a[1];
- React.useEffect(function () {
- destroyRef.current = false;
- return function () {
- destroyRef.current = true;
- };
- }, []);
- function safeSetState(updater, ignoreDestroy) {
- if (ignoreDestroy && destroyRef.current) {
- return;
- }
- setValue(updater);
- }
- return [value, safeSetState];
- }
|