Skip to main content

Event Handling

Event Types

All event types are documented in the AppEvents enum documentation page.

Reactive Hooks

You often won't need to listen to an event directly and can instead rely on our Reactive Hooks:

Listening to Events

We strongly recommend you always use our pre-packaged hooks for registering event listeners. These hooks cleanup after themselves automatically to avoid memory leaks.

useAPIEventListener(
AppEvents.ClickRemReference, // App event id
'workspace', // event key for keyed events, else undefined
(data) => {
// event callback
/* ... */
},
);

Global and Keyed Events

Events can either be "Global" or "Keyed".

  • Keyed Events trigger for individual items, such as AppEvents.RemChanged. See the AppEvents enum for documentaiton on each key type.

For event types which require an event key, pass the key as the third argument to useAPIEventListener.:

useAPIEventListener(AppEvents.RemChanged, rem._id, () => {
/* ... */
});
  • Rem Events (key=RemId):

    • AppEvents.RemChanged
  • Powerup Events (key=PowerupCode):

    • AppEvents.ClickRemReference
  • Special Events

    • AppEvents.MessageBroadcast (key = Message Channel)
    • AppEvents.SettingChanged (key = Setting ID)
    • AppEvents.StorageSessionChange (key = Storage Key)
    • AppEvents.StorageSyncedChange (key = Storage Key)
    • AppEvents.StorageLocalChange (key = Storage Key)
  • Global Events trigger when for events that effect the entire app, such as AppEvents.QueueEnter.

You do not need to pass an event key to listen to a global event:

useAPIEventListener(AppEvents.QueueEnter, undefined, () => {
/* ... */
});
  • Global Events (key=undefined):
    • AppEvents.GlobalOpenRem
    • AppEvents.URLChange
    • AppEvents.QueueCompleteCard
    • AppEvents.QueueEnter
    • AppEvents.QueueExit
    • AppEvents.EditorSelectionChanged
    • AppEvents.EditorTextEdited
    • AppEvents.ClickSidebarItem