feat(useRefMounted): remove obsolete hook;

This commit is contained in:
xobotyi 2019-11-01 00:13:57 +03:00
parent 5d97bf1d37
commit dc364c851c
5 changed files with 1 additions and 77 deletions

View File

@ -111,7 +111,7 @@
- [`useEffectOnce`](./docs/useEffectOnce.md) — a modified [`useEffect`](https://reactjs.org/docs/hooks-reference.html#useeffect) hook that only runs once.
- [`useEvent`](./docs/useEvent.md) — subscribe to events.
- [`useLifecycles`](./docs/useLifecycles.md) — calls `mount` and `unmount` callbacks.
- [`useMountedState`](./docs/useMountedState.md) ~~and [`useRefMounted`](./docs/useRefMounted.md)~~ — track if component is mounted.
- [`useMountedState`](./docs/useMountedState.md) — track if component is mounted.
- [`usePromise`](./docs/usePromise.md) — resolves promise only while component is mounted.
- [`useLogger`](./docs/useLogger.md) — logs in console as component goes through life-cycles.
- [`useMount`](./docs/useMount.md) — calls `mount` callbacks.

View File

@ -1,28 +0,0 @@
# `useRefMounted`
>**DEPRECATED**
>This method is obsolete, use `useMountedState` instead.
Lifecycle hook that tracks if component is mounted. Returns a ref, which has a
boolean `.current` property.
## Usage
```jsx
import {useRefMounted} from 'react-use';
const Demo = () => {
const refMounted = useRefMounted();
useEffect(() => {
setTimeout(() => {
if (refMounted.current) {
// ...
} else {
// ...
}
}, 1000);
});
};
```

View File

@ -1,21 +0,0 @@
import { storiesOf } from '@storybook/react';
import * as React from 'react';
import { useRaf, useRefMounted } from '..';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const refMounted = useRefMounted();
useRaf();
return (
<div>
<h3>**DEPRECATED**</h3>
<h4>This method is obsolete, use `useMountedState` instead.</h4>
<span>is mounted: {refMounted.current ? '👍' : '👎'}</span>
</div>
);
};
storiesOf('Lifecycle|useRefMounted', module)
.add('Docs', () => <ShowDocs md={require('../../docs/useRefMounted.md')} />)
.add('Demo', () => <Demo />);

View File

@ -64,10 +64,6 @@ export { default as usePromise } from './usePromise';
export { default as useRaf } from './useRaf';
export { default as useRafLoop } from './useRafLoop';
export { default as useRafState } from './useRafState';
/**
* @deprecated This hook is obsolete and Will be removed soon, use `useMountedState` instead
*/
export { default as useRefMounted } from './useRefMounted';
export { default as useSearchParam } from './useSearchParam';
export { default as useScroll } from './useScroll';
export { default as useScrolling } from './useScrolling';

View File

@ -1,23 +0,0 @@
import { RefObject, useEffect, useRef } from 'react';
/**
* @deprecated This hook is obsolete, use `useMountedState` instead
*/
const useRefMounted = (): RefObject<boolean> => {
const refMounted = useRef<boolean>(false);
useEffect(() => {
refMounted.current = true;
return () => {
refMounted.current = false;
};
}, []);
return refMounted;
};
/**
* @deprecated This hook is obsolete, use `useMountedState` instead
*/
export default useRefMounted;