handleOnClick run immediately
utxo-detective opened this issue · 1 comments
utxo-detective commented
I would like to add a click listener on a ToastMessage so I can link to other parts of my website.
When passing handleOnClick as a prop like this:
this.refs.toastContainer.success(
'this is a message',
'this is a title',
{ closeButton: true, handleOnClick: this.redirect(sentence.url) }
);
redirect(url) {
browserHistory.push(url);
}
the click callback runs when the toast appears, not when the toast is clicked on. I beleive the reason is on line 91 of ToastContainer.js
handleOnClick: (e) => {
if (`function` === typeof optionsOverride.handleOnClick) {
optionsOverride.handleOnClick();
}
return this._handle_toast_on_click(e);
},
Shouldn't the handleOnClick be passed down to the ToastMessage instead of running on creation?
If I am doing something wrong, let me know. If this is a bug, I am happy to make a pr
utxo-detective commented
Okay, I was able to figure it out and your code is fine. I needed to pass an anonymous function like so
this.refs.toastContainer.success(
'this is a message',
'title',
{ closeButton: true, handleOnClick: function() { this.redirect(sentence.url) }
);
hope this helps anyone with the same problem. Closing the issue