Hooks
useEvent
#
The useEvent
React Hook allows us to register a new callback function to the passed Event.
The advantage of using this Hook instead of the on
method in a React Component,
is that the registered callback function gets automatically unregistered whenever the Component unmounts.
#
๐ด ExampleLive Editor
Result
#
๐ฆ TypescriptuseEvent
is almost 100% typesafe.
#
๐ญ PropsProp | Type | Description | Required |
---|---|---|---|
event | Event (E) | Event to which the passed callback function gets applied. | Yes |
callback | EventCallbackFunction<E['payload']> | Callback Function that gets applied to the passed Event | Yes |
key | string | number | Key/Name of created Observer. Mainly thought for Debugging. | No |
agileInstance | Agile | To which Agile Instance the Event get bound. Gets autodetect! | No |
#
๐ ReturnuseEvent
returns nothing.