-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 component stale messages state issue, while quickly calling toastRef.show #1804
Comments
Hi, Unfortunately, I didn't fully understand this problem. Do you have a codesandbox link for us to replicate? Also, We would be grateful if you create a PR with the possible solution. Best Regards, |
here is codesandbox with regeneration of the issue, https://codesandbox.io/s/awesome-johnson-csvdh
|
Ref will hold one (unique) reference of the selected HTML element. in your example, you trigger 'show' twice on the same element and that causes you to override the first call. Fortunately, Primereact docs explain how to triggers multiple toast/messages at the same time. it's fairly simple, you pass an array instead of a single object. Knowing that you can refactor your function const showMultiple = () => {
toast.current.show(
{severity:'info', summary:'Message 1', detail:'First message', life: 3000});
toast.current.show(
{severity:'info', summary:'Message 2', detail:'Second Message', life: 3000});
} to the following const showMultiple = () => {
toast.current.show([
{severity:'info', summary:'Message 1', detail:'First message'},
{severity:'info', summary:'Message 2', detail:'Second message'},
]);
} And it should work as intended =) |
@callmephil i already have mentioned this solution in my previous comment, but just think about async events, which may fire at the same time, and it's not that much hard to solve as mentioned in original issue statement. |
@prakash1998 Would a "throttling" pattern work for your async use case? |
yes it works, i have tested on my side, and already using fork of it in my project temporarily. |
I think this will be fixed by this PR: #2669 |
This is fixed in 8.0.0-RC1 now that hooks are being used: https://codesandbox.io/s/primereact-test-forked-5zuel3 |
then it's ignoring msg2 and now state = { messages : [msg1,msg3] } ( consider msg are sticky )
Reason : it is because show method is using this.state.messages when updating state, so when i call it quickly for multiple time, then all calls have old state
Solution: you can use fresh state which calling setState like this
i would like to submit merge request if you want me to, thanks.
The text was updated successfully, but these errors were encountered: