Skip to content

Commit 161de6e

Browse files
docs
1 parent 7f50e2b commit 161de6e

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-use-custom-hooks
22

3-
A collection of react custom hooks
3+
A collection of react custom hooks in typescript
44

55
# Installation
66

@@ -15,9 +15,6 @@ yarn add react-use-custom-hooks
1515
import { useSafeState } from 'react-use-custom-hooks';
1616
```
1717

18-
# Hooks list
18+
# Demo
1919

20-
1. useDebounce
21-
2. useSafeState
22-
3. useIsMounted
23-
4. usePrevious
20+
https://react-use-custom-hooks.vercel.app/

docs/docs/usePrevious.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you want to access the previous props or state in functional components, you
77
### Usage example
88

99
```typescript
10-
const [value, setvalue] = useState(initialState);
10+
const [value, setValue] = useState(initialState);
1111
const previousValue = usePrevious(value);
1212
```
1313

docs/docs/useSafeState.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# useSafeState
22

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.
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 operation like AJAX calls.
44

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.
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.
66

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.
7+
For small applications, leaking memory might not be a big issue since there is not much client side navigation happening and the memory will get cleared on reload. But for large applications, especially large single page applications, it can be a problem since the user navigates to multiple pages of the application over time without reloading the app and thus if there is any leak it will grew over time causing the app to break eventually.
8+
9+
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 just ignore the `setState` call. The API is same as react's `useState` hook, so you can use this hook instead of `useState` for asynchronous operation to avoid any memory leak.
810

911
<pre>{`import {useSafeState} from 'react-use-custom-hooks';`}</pre>
1012

1113
### Usage example
1214

1315
```typescript
14-
const [value, setvalue] = useSafeState(initialState);
16+
const [value, setValue] = useSafeState(initialState);
1517
```
1618

1719
### Playground

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"type": "git",
1515
"url": "https://github.com/aldrinpvincent/react-use-custom-hooks"
1616
},
17+
"homepage": "https://react-use-custom-hooks.vercel.app/",
1718
"scripts": {
1819
"start": "tsdx watch",
1920
"build": "tsdx build",
@@ -40,7 +41,7 @@
4041
"name": "react-use-custom-hooks",
4142
"author": "aldrinpvincent",
4243
"module": "dist/react-custom-hooks.esm.js",
43-
"description": "A collection of react custom hooks in typescript",
44+
"description": "A utility to cache api calls in JavaScript by memoizing promises",
4445
"size-limit": [
4546
{
4647
"path": "dist/react-custom-hooks.cjs.production.min.js",

0 commit comments

Comments
 (0)