npm.io
1.0.3 • Published 5 years ago

@formoe/use-app-messages

Licence
MIT License
Version
1.0.3
Deps
2
Size
11 kB
Vulns
0
Weekly
0

use-app-messages

A hook providing a context wrapper and api to set and manage messages.

A Message is an object containing a text and a type.

Create the context like this:

import { MessageProvider } from "./index"

<MessageProvider>
  <YourComponent />
</MessageProvider>

now in the component tree inside the provider you can:

import { useAppMessages, MESSAGE_TYPES } from "./index"

const { addMessage, acknowledge, messages } = useAppMessages()

and then:

  • add a Message via e.g addMessage({text: "some text", type: MESSAGE_TYPES.info})
  • acknowledge a Message via e.g. acknowledge(0)
  • read all messages

AppMessages

With:

import { AppMessages } from "./index"

<AppMessages />

you can integrate a themed component using the hook to show all app messages.