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
- A _useState_ that receives an object, with _value property.
7
+
- A _useEvents_ that returns _addListener_ function.
8
+
- A child component that has _useEvents_ that returns _dispatch_ function and renders an input text with an onChange handler that invoke the _dispatch_ function with a custom event with type _demo_ and with a custom event with input value as _detail_.
9
+
10
+
The main component calls _addlistener_ that updates component state inside an useEffect, in this way the listener _addListener_ is done only once and when the component is unmounted, it executes the _unlisten_.
- A _useState_ that receives an object, with _value property.
7
-
- A _usePubSubModel that receives __demo__ as topic and returns an object with _publish_ and _subscribe_ functions.
8
-
- A child component that receives _publish function_ as prop and renders an input text with an onChange handler that invoke the publish function with input value as param.
7
+
- A _usePubSubModel_ that receives __demo__ as topic and returns the _subscribe_ function.
8
+
- A child component that use _usePubSubModel_ to get _publish_ function and renders an input text with an onChange handler that invoke the publish function with input value as param.
9
9
10
10
The main component subscribe a listener, that updates component state, to the topic __demo__ inside an useEffect, in this way the listener _subscription_ is done only once and when the component is unmounted, it executes the _unsubscription_. The _subscription_ can be done outside useEffect also, what's important is that listener doesn't change when component rerenders (so it can be declared outside the component or with useCallback for example). In this case the _unsubscription_ is executed from hook.
Communication system based on Events pattern implemented on a EventTarget subclass. AddListener and dispatch functions to communicate. The result of invoking the _addListener_ function in turn returns a function that can be used to _removeListener_ on event. Otherwise, the listener is automatically removed when the component that has instantiated it is unmounted.
> - A _useState_ that receives an object, with _value property.
42
+
> - A _useEvents_ that returns _addListener_ function.
43
+
> - A child component that has _useEvents_ that returns _dispatch_ function and renders an input text with an onChange handler that invoke the _dispatch_ function with a custom event with type _demo_ and with a custom event with input value as _detail_.
44
+
>
45
+
> The main component calls _addlistener_ that updates component state inside an useEffect, in this way the listener _addListener_ is done only once and when the component is unmounted, it executes the _unlisten_.
> - A _useState_ that receives an object, with _value property.
41
-
> - A _usePubSubModel that receives __demo__ as topic and returns an object with _publish_ and _subscribe_functions.
42
-
> - A child component that receives _publish function_ as prop and renders an input text with an onChange handler that invoke the publish function with input value as param.
42
+
> - A _usePubSubModel_ that receives __demo__ as topic and returns the _subscribe_function.
43
+
> - A child component that use _usePubSubModel_ to get _publish_ function and renders an input text with an onChange handler that invoke the publish function with input value as param.
43
44
>
44
45
> The main component subscribe a listener, that updates component state, to the topic __demo__ inside an useEffect, in this way the listener _subscription_ is done only once and when the component is unmounted, it executes the _unsubscription_. The _subscription_ can be done outside useEffect also, what's important is that listener doesn't change when component rerenders (so it can be declared outside the component or with useCallback for example). In this case the _unsubscription_ is executed from hook.
0 commit comments