react-toastify icon indicating copy to clipboard operation
react-toastify copied to clipboard

Unexpected behavior with combination: update & limit

Open KubaChoice opened this issue 3 years ago • 3 comments

When you try following code when toast container have set limit=1, expected behavior should be same in both runs, but it is not, in the second run it shows fist message and not last (updated):

function onClick() {
  const id = toast.success('a')
  toast.update(id, {render: 'b'})
  toast.update(id, {render: 'c'})
}

onClick();
onClick();

During first "onClick()" run is eventually (instantly) showed 'c' After close (manually or after time out), second "onClick()" show 'a' (even twice - but this can be related with another issue)

KubaChoice avatar Aug 16 '22 01:08 KubaChoice

@KubaChoice can you reproduce the issue on codesanbox or share a repository thank you

fkhadra avatar Aug 18 '22 19:08 fkhadra

Hi There it is: https://codesandbox.io/s/toastify-update-que-issue-eo21yj?file=/src/index.js

  • it seems that update() method works only on active notifications

This is very nice tool, however working with queue is limited, it is pity Working with queue (in my case) missing at least following:

  • update queued notifications (this issue)
  • check if notification (id) is queued
  • remove specific notification (id) from queue
  • add/relocate notification (id) to queue to specified position

In this case I'm "forced" to write own queue Still nice tool

KubaChoice avatar Aug 19 '22 09:08 KubaChoice

Hey @KubaChoice, you're right. update only works with active notification. I think I could address the following point in a future version as they make sense

  • update queued notifications (this issue)
  • check if notification (id) is queued
  • remove specific notification (id) from queue

Regarding add/relocate notification (id) to queue to specified position, not too complicated to implement but It might require a bit more time to get the API right.

fkhadra avatar Aug 19 '22 11:08 fkhadra