Skip to content
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

Messages/Toast: fix/add replace(newMessages) method #2925

Closed
inad9300 opened this issue May 25, 2022 · 2 comments · Fixed by #2932
Closed

Messages/Toast: fix/add replace(newMessages) method #2925

inad9300 opened this issue May 25, 2022 · 2 comments · Fixed by #2932
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@inad9300
Copy link
Contributor

Describe the bug

When wanting to show only a single message (the latest) in a particular area of the application, one would expect that calling clear() and then show({ ... }) would achieve this. However, when calling clear() followed by show(), the call to clear() is ignored, and new messages keep being added.

Reproducer

https://codesandbox.io/s/dreamy-mccarthy-8u7oui?file=/src/demo/MessagesDemo.js

PrimeReact version

8.0.1

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. Go to link
  2. Click the button multiple times
  3. See that new messages keep appearing
  4. Compare with code to realize that new messages should not keep appearing

Expected behavior

No response

@inad9300 inad9300 added the Type: Bug Issue contains a defect related to a specific component. label May 25, 2022
melloware added a commit to melloware/primereact that referenced this issue May 25, 2022
@melloware melloware self-assigned this May 25, 2022
@melloware melloware added this to the 8.2.0 milestone May 25, 2022
@melloware melloware linked a pull request May 25, 2022 that will close this issue
@melloware
Copy link
Member

melloware commented May 25, 2022

OK you don't want to call clear() then show() because both update the same state variable in the hook. That is why there is the replace method to accomplish exactly what you want in1 line effectively calling clear and show together.

messages.current.replace(newMessages);

however I found a bug in it which I am fixing for 8.2.0

melloware added a commit to melloware/primereact that referenced this issue May 25, 2022
@melloware melloware changed the title Messages: clear() is ignored when followed by show() Messages/Toast: fix/add replace(newMessages) method May 25, 2022
@melloware
Copy link
Member

I also synchronized Toast to have the same behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants