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
- An _inputRef_ ref variable attacched to an input element contained in a form.
8
+
- An dispatch function returned from _useEventDispatcher_ with _inputRef_ as element.
9
+
- An onSubmit function to handle form onSubmit that invokes _dispatch_ function with a CustomEvent("demo") which detail is valued with input value taken from onSubmit event.
10
+
- A useEventListener of type _demo_, on element _inputRef_ and with a listener that takes CustomEvent and invokes setState with event detail.
> - An _inputRef_ ref variable attacched to an input element contained in a form.
39
+
> - An dispatch function returned from _useEventDispatcher_ with _inputRef_ as element.
40
+
> - An onSubmit function to handle form onSubmit that invokes _dispatch_ function with a CustomEvent("demo") which detail is valued with input value taken from onSubmit event.
41
+
> - A useEventListener of type _demo_, on element _inputRef_ and a listener that takes CustomEvent and invokes setState with event detail.
Copy file name to clipboardExpand all lines: apps/react-tools-demo/src/markdown/useEventListener.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,10 +25,11 @@ export { UseEventListener };
25
25
```
26
26
27
27
> The component has:
28
-
> - A _buttonRef_ ref variable linked to an button node element.
28
+
> - A _buttonRef_ ref variable linked to an button node element with text click to log.
29
29
> - A _useEventListener_ invocation with these options: _type_="click", _listener_=(e:Event)=>console.log(e). So the eventListener is attached to window and the invocation result is used to initialize a variable remove that remove the eventListener.
30
30
> - A _useEventListener_ invocation like that above but attached at button node by _buttonRef_ with _listenerOpts_ capture=_true_ and that stops event propagation.
31
-
> - A button that, if clicked, invokes the removeEventListener
31
+
> - A _button_ with text Remove that, if clicked, invokes the removeEventListener.
32
+
>
32
33
> At every click on Demo area the eventListener attached on object window logs in console the event, while the eventListener attached on button logs when button is clicked. When button remove is clicked it removes the eventListener on window object. The button eventListener is removed during component unmount.
* **`useMemoizedFunction`**: Hook to store a function that will never change while keeping its dependencies always up to date. Can be used instead of _useCallback_, without esplicity dependencies array.
0 commit comments