@hcfy/create-toaster
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

Toaster.create() of Blueprintjs v5 uses ReactDOM.render(), which will generate warnings in React 18, so I created this module to replace Toaster.create().

Before:

const toaster = Toaster.create(props, container)

After:

import { createToaster } from '@hcfy/create-toaster'

const toasterPromise = createToaster(props, container)

toasterPromise.then(toaster =>{
  toaster.show({ message: 'Hello toaster!' })
})

You can also use the following hook to use it synchronously in function components:

import { createToaster, useToasterState }  from '@hcfy/create-toaster'

const toasterPromise = createToaster(props, container)

function App() {
  const toaster = useToasterState(toasterPromise)

  useEffect(() => {
    toaster?.show({ message: 'Hello toaster!' })
  }, [toaster])
}

or:

import { createToaster, useToasterRef }  from '@hcfy/create-toaster'

const toasterPromise = createToaster(props, container)

function App() {
  const toasterRef = useToasterRef(toasterPromise)

  useEffect(() => {
    toasterRef.current?.show({ message: 'Hello toaster!' })
  }, [toasterRef.current])
}

/@hcfy/create-toaster/

    Package Sidebar

    Install

    npm i @hcfy/create-toaster

    Weekly Downloads

    3

    Version

    3.1.0

    License

    MIT

    Unpacked Size

    6 kB

    Total Files

    5

    Last publish

    Collaborators

    • milklee