Skip to main content

Display notifications

Oneki.js provides the useNotifications hook to retrieve notifications for a specific topic.
As soon as the topic is updated, the component does a re-render.

const notifications = useNotifications(topic)


note

Oneki.js provides a default service to send notifications, but not a default widget to handle them. You have to provide it

Parameters

Inputs

ParameterTypeDescription
topic*stringtopic is a entry in the Redux state, stored under "notifications.(topic)

Example: if topic=error, then the entry in Redux state is: notifications.error
The value of notifications.error is an array of notifications

Outputs

The output is an array of Notification which is an object with the following attributes:

AttributeTypeDescription
topicstringThe topic to be used to send the notification
idstringUnique ID of the notification. This id is used later to remove the notification from the Redux state
ttlnumberTime to leave of the notification in milliseconds. Set the value to 0 for no expiration

Defaults to: ttl in settings.ts. If not defined in settings.ts, then defaults to 5000 (0 for error topic)
persistbooleanA flag to indicate if the notification should survive after a route change.

Defaults to: persist in settings.ts. If not defined in settings.ts, then defaults to true
payloadobjectThe payload of the notification. We recommand an object with at least the field message
Example: { message: "test" }

Examples

Minimal example

examples/cra-notifications/src/components/NotificationCenter.tsx
loading...