-
-
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
Prevent Duplicates #3
Comments
I'm glad you like it! Good idea. I'll add a props |
The messages are transformed to a react component. You can also pass a component if you want too. |
Hey @dekelb when you say "Prevent Duplicates" you mean show only one toast at time? |
Duplicates means if msg1 and msg2 have exactly the same content, don't show msg2. For example: There will be only two toastrs (1 and 3) because the content of 1 and 2 is exactly the same. |
The role of the library is only to display a notification. |
I think that this feature is a very important one, and other toastr components has it so it's really a good one to have (and not really hard to implement). Also - if you have multiple components in the page that generate toastrs - as a developer it will require you to manage a wrapper for the toastr to decide if to show some message or not (and this doesn't really make any sense). |
You got me with: Another question comes to my mind. If I don't show duplicate should I reset the timer for the notification? |
No, I don't think you need to reset the time :) |
Regarding the implementation, It's not as easy as you think. There are three use cases:
toast("hello");
// Somewhere in the library code
if (isNumber(toastContent) || isString(toastContent)) {
toastContent === anotherContent
}
toast(<MyComponent />);
// Somewhere in the library code
toastContent.type.name === MyComponent
toast(<div>plop</div>);
// toastContent.type will be equal to `div` so there is no way to check equality I could prevent duplicates only for string, number and named component. toast("hello", {
preventDuplicate: id-foo
});
//somewhere else
toast("hello", {
preventDuplicate: id-foo
}); I guess I need to find something else. Any idea is appreciated |
Intead of accepting a string accept an object with There may be case that the message is same and I don't wan't to prevent duplicate and change the UI. In that case if you handle equality by your own, I won't be able to do that. |
This seems like something that'd be trivial to do as a developer just by writing your own |
any solution to avoid displaying duplicate messages? |
Hey @zeeshanjan82, I will be able to work on the version 2 next week. I think I'll choose the solution proposed by @ritz078, what do you think ? |
The api allow to check if a toast is running based on the ID. Doing so it's easy to prevent duplicate toast
Hey @manishbhatt94, May I ask you to reproduce the issue on codesandbox for example, so I'll be able to help you? Thanks |
Hey sorry for the late reply. |
i still have the duplicate problem |
1 similar comment
i still have the duplicate problem |
Same, has the prop not been added yet? If only I had more time I'd make a PR myself... |
I have solved duplicate toast issue as mentioned in their docs |
I did not see any option in their docs about preventing duplicates, but I checked on the source and you can achieve preventing duplicates by specifying the
In my particular case, I just used my toast message (which is always a string) as the
|
First - thanks for this project!
Is it possible to add an option to prevent duplicated messages?
Other toastr libraries have this feature and I really think it's a good one.
Thanks!
The text was updated successfully, but these errors were encountered: