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
Same as React's `useCallback`, but returns a stable reference.
3
+
4
+
This library is a user-land implementation of the `useEvent` hook, [proposed in this RFC](https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md).
5
+
6
+
# Installation
7
+
8
+
```sh
9
+
npm install react-useevent
10
+
```
11
+
12
+
# Usage
13
+
(this example was copied from the RFC)
14
+
15
+
You can wrap any event handler into `useEvent`.
16
+
17
+
```js
18
+
importuseEventfrom'react-useevent';
19
+
20
+
functionChat() {
21
+
const [text, setText] =useState('');
22
+
23
+
constonClick=useEvent(() => {
24
+
sendMessage(text);
25
+
});
26
+
27
+
return<SendButton onClick={onClick} />;
28
+
}
29
+
```
30
+
31
+
The code inside `useEvent` “sees” the props/state values at the time of the call.
32
+
The returned function has a stable identity even if the props/state it references change.
0 commit comments