Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to open a Toast? #7627

Closed
biapar opened this issue Jan 22, 2021 · 2 comments
Closed

How to open a Toast? #7627

biapar opened this issue Jan 22, 2021 · 2 comments

Comments

@biapar
Copy link

biapar commented Jan 22, 2021

I try to open a toast when I press a button, but I don’t understand how.
Is there an example?

@joshblack
Copy link
Contributor

Hi there, @biapar! 👋

Currently, there is no example for rendering/placement of the notifications. We provide the component itself, but it is up to teams to determine the placement. We have some guidelines over on the component page itself that might help: https://www.carbondesignsystem.com/components/notification/usage

Hope this helps!

@Reve
Copy link

Reve commented Mar 4, 2022

Since there is no offical example, the only way I made it work so you can show it and re-show it after it was dissmised is to use a state variable "open" that starts initialy with 0 (which can also be interpreted as false) and check for the value in the render() function. To reshow it I use Math.random() to generate a random value for "open" and used the key property of the Notification.

See example:

const [open, setOpen] = useState(0)

handleSuccess = () => setOpen(Math.random())

render (
   {!!open &&
      <ToastNotification
         key={open}
         kind="success"
         title="This is a toast"
         timeout={5000}
      />
   }
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants