React-toastify: Is there a callback?

Created on 3 Apr 2018  路  10Comments  路  Source: fkhadra/react-toastify

Hello, my question is this:
Does this have a callback? I need to click to redirect me to another page

notify () {
    toast.error(
        <spam><i className="fa fa-exclamation-circle" style={{ fontSize: 20, marginLeft: 10 }} />
            <spam style={{ marginLeft: 10, fontSize: 10 }}> Error en un servicio </spam>
        </spam>, {
            className: ({
                top: 40
        })
    })
}

Thank you!
Sorry for my English! I'm not very good...

question

Most helpful comment

@fkhadra not exactly.

If user closes toast by clicking on x button, toast should dismiss.
If user clicks on toast, then I want to perform some action (redirect to page, for example).

Chrome notifications work like I want to implement on page.

All 10 comments

Hello @Zequee98,

You can add callback when the toast open and when it closes. Define callback.

Is it what you are looking for ?

Thanks

Yes, but I need it to be when I click on the notification and redirect to another page.
I do not want to be redirected when I open or close the notification!
:+1:
Thanks

Something like a 'onClick'

Why not simply put a onClick event on your component like so:

 toast.error(
        <spam onClick={doSomething}><i className="fa fa-exclamation-circle" style={{ fontSize: 20, marginLeft: 10 }} />
            <spam style={{ marginLeft: 10, fontSize: 10 }}> Error en un servicio </spam>
        </spam>, {
            className: ({
                top: 40
        })
    })

What a teacher! Thank you!!
:+1:

You're welcome

@fkhadra unfortunatelly, with your solution user can click outside the rendered span/div, and just close toast without being redirected to other page. Having onClick for toast would be very great for that case.

Hey @Strate,

You want to redirect the user or perform any action when the user closes the toast right ?

@fkhadra not exactly.

If user closes toast by clicking on x button, toast should dismiss.
If user clicks on toast, then I want to perform some action (redirect to page, for example).

Chrome notifications work like I want to implement on page.

I tried to use onOpen - onClose callback but those work even when user clicks or not over toast, any idea?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fkhadra picture fkhadra  路  3Comments

spiritedfang picture spiritedfang  路  3Comments

jorgecuesta picture jorgecuesta  路  5Comments

billtlee picture billtlee  路  5Comments

fkhadra picture fkhadra  路  4Comments