Skip to content

Commit 9fa8140

Browse files
Yair Even OrYair Even Or
authored andcommitted
2 parents 3b7e548 + 7b840fd commit 9fa8140

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img src="readme-header.svg"/ >
44
</a>
55
</p>
6-
<h3 align="center">Watch <code>ref</code> changes with conditional re-renders</h3>
6+
<h3 align="center">👀 Watch <code>ref</code> changes with conditional re-renders</h3>
77
<p align='center'>(First draft - expect changes) <a href='https://codesandbox.io/s/ref-change-listener-m5bupr?file=/src/List.js'>Live demo</a></p>
88

99
---
@@ -24,17 +24,21 @@ possibly all the sub-tree as well, which is useless and even harmful for perform
2424
Each sub-component can register a listener for changes in a specific `ref` or any of its `current` property's properties
2525
(assuming `current` points to a mutated Object/Array).
2626

27-
## Install:
27+
<br>
28+
29+
## Install with:
2830

2931
Use from [CDN](https://unpkg.com/@yaireo/react-ref-watcher) / Download from this repo / [NPM](https://www.npmjs.com/package/@yaireo/react-ref-watcher)
3032

3133
```bash
3234
npm i @yaireo/react-ref-watcher -S
3335
```
3436

37+
<br><br>
38+
3539
## What's in this package?
3640

37-
### `useWatchableRef`
41+
### 1️⃣ `useWatchableRef`
3842

3943
| Argument | Type | Info
4044
|---------------|-------|-------------------------------------------------------------
@@ -53,7 +57,9 @@ const Component = () => {
5357
}
5458
```
5559

56-
### `useWatchableListener`
60+
<br>
61+
62+
### 2️⃣ `useWatchableListener`
5763

5864
| Argument | Type | Info
5965
|----------|----------|-------------------------------------------------------------
@@ -78,8 +84,9 @@ const Component = ({ ref1 }) => {
7884
}
7985
```
8086

87+
<br>
8188

82-
### `useWatchableEffect`
89+
### 3️⃣ `useWatchableEffect`
8390

8491
| Argument | Type | Info
8592
|---------------|----------|-------------------------------------------------------------
@@ -102,8 +109,9 @@ const Component = ({ ref1, ref2 }) => {
102109
}
103110
```
104111

112+
<br>
105113

106-
### `propWatcher`
114+
### 4️⃣ `propWatcher`
107115

108116
Unlike the other hooks, this is a utility function which does the actual watching.
109117
It adds an enumerable `__WATCHERS` property (will host callback listeners when changes detected)
@@ -112,6 +120,7 @@ on top of the argument (expected to be an *Object*) and then returns a new `prox
112120
Every time a propery is modified or deleted (in your code) the proxy trap will fire and all
113121
callback functions defined in the `__WATCHERS` property will fire.
114122

123+
Any Object may be wrapped with `propWatcher` to become "watchable" (not only React refs).
115124
**Example of most basic usage:**
116125

117126
```js

0 commit comments

Comments
 (0)