-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
toast.update() not working? #135
Comments
Hello @rezmoth, The update is working as expected. What you can do is to track the toastId and the one inside the callback to ensure they are the same. EDIT: the animation has been fixed |
I'm trying to integrate react-toastify with redux to give feedback to the user about different application states. The toast displays with the message "Submission in progress", but the update doesn't take place when the form is submitted. import { ToastContainer, toast } from 'react-toastify';
const reducer = combineReducers({
form: formReducer.plugin({
dynamicForm: (state = {
fetching: false,
posting: false,
toastId: null
}, action) => {
switch(action.type) {
case "FORM_IS_SUBMITTING":
let t_id = toast("Submission in progress, please wait...", { autoClose: false }); // can create toast no problem
console.log(t_id);
return Object.assign({}, state, { toastId: t_id, posting: action.isPosting })
case "SUBMIT_FORM_DATA":
const { toastId } = state;
if(toastId >= 0) {
console.log(toastId); // matches originally logged t_id from above
console.log(toast.isActive(toastId)) // true
toast.update(toastId, "Submission Complete.", { type: toast.TYPE.INFO, autoClose: 5000 }); // does nothing
} else {
toast("Submission Complete.", { type: toast.TYPE.INFO, autoClose: 5000 });
}
return Object.assign({}, state, { posting: action.isPosting });
default:
return state
}
}
}),
}); Am I overlooking something? |
I to am having difficulties with setTimeout(() => {
toast.update(toastID, { render: "hello world" } );
}, 0); however, outside of the timeout, |
Hey @maxchehab, Are you using redux as well ? |
Can someone setup a boilerplate with redux on codesandbox to help me debug ?
|
I am not using redux. I think it has to do with the callstack. Running it inside of |
oh sorry @maxchehab, I misunderstood you. Actually when I display a toast I already push it at the end of the callstack. You can look at the source of the EventManager. But I'll implement a queu for the update and see if it fix your issue like you suggested |
Hello @fkhadra I believe it has to do with consecutive calls to setState as consecutive calls are 'discarded', altought I haven't checked the source code. Hope this helps. Thanks |
@rezmoth You're probably right. It's not working at all when updating the toast too fast.
|
Off topic toast.update(this.toastId, "Enteprise created successfully.", {
type: toast.TYPE.SUCCESS,
autoClose: 5000
});
// need to be
toast.update(this.toastId, {
render: "Enteprise created successfully.",
type: toast.TYPE.SUCCESS,
autoClose: 5000
}); Maybe it could be useful to accept both. I found a solution but if the update occurs too fast you won't see the first message. |
@rezmoth I forked your sandbox with the hotfix: @maxchehab and @DreadfulDeveloper could you update to the latest version v3.3.4 and see if it fix your issue, please. |
Seems to be working, yes, if the update is too fast (which it is) I won't see the first toast, but placing a breakpoint and continuing execution it does show both toasts (for verifying purposes). Thanks |
Thank you @rezmoth for the feedback. @maxchehab I close the issue, if yours is still not fixed, feel free to open a new one. |
Toast Update not working:
... Component omited for brevity ...
It just displays Hello Toast it doesn't change even when the insertion to collection succeed. I'd expect it to update from info toast to success toast but I don't know why doesn't. How can I fix it for the intended result? Thanks
The text was updated successfully, but these errors were encountered: