You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/useIsMounted.md
+3-18Lines changed: 3 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
This hook is used to check whether the component is mounted or not. This hook will return a function which will return a boolean value stating the component is mounted or not on calling. This will be useful if you want to perform some operation based on component is mounted or not like stop polling an api, update state etc.
4
4
5
+
<pre>{`import {useIsMounted} from 'react-use-custom-hooks';`}</pre>
6
+
5
7
### Usage example
6
8
7
9
```typescript
@@ -37,23 +39,6 @@ function IsMountedExample(props) {
This hook works similar to `this.setState` works in react class components. Here when you call `setState`, it shallow merges state partial into current state. It will be useful when you want change a class component to functional component.
4
+
5
+
<pre>{`import {useLegacyState} from 'react-use-custom-hooks';`}</pre>
Copy file name to clipboardExpand all lines: docs/docs/usePrevious.md
+8-21Lines changed: 8 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
If you want to access the previous props or state in functional components, you can use the `usePrevious` hook. This hook would work for props, state, or any other calculated value.
4
4
5
+
<pre>{`import {usePrevious} from 'react-use-custom-hooks';`}</pre>
6
+
5
7
### Usage example
6
8
7
9
```typescript
@@ -18,14 +20,16 @@ function PreviousStateExample(props) {
18
20
19
21
return (
20
22
<div>
21
-
Current value:<b>{count}</b>, Previous value:<b>{prevCount}</b>
A memory safe version of react's `useState` hook. In reactmemory leak occurs when `setState` operation performed on an unmounted component and leak happens mostly with asynchronous opration like AJAX calls.
3
+
A memory safe version of react's `useState` hook. In react, on way memory leak occurs when `setState` operation performed on an unmounted component and it happens mostly with asynchronous opration like AJAX calls.
4
4
5
5
For example, if the user initiated an AJAX call and navigated away from tha page before the call is returned, the component will get unmounted and when the api call is fulfilled, the `setstate` will be performed on the unmounted component causing a memory leak.
6
6
7
7
This hook will prevent these kind of memory leaks by checking whether the component is mounted before `setstate` operation, if the component is unmounted, it will jsut ignore the `setstate` call. The API is same as react's `useState` hook, so you can use this hook instead of `useState` for asynchronous opration to avoid any memory leak.
8
8
9
+
<pre>{`import {useSafeState} from 'react-use-custom-hooks';`}</pre>
0 commit comments