Skip to content

Publish Latest value #219

@ritsrivastava01

Description

@ritsrivastava01

Dear @mroderick ,

Thanks for this awesome library 👍 .

I'm facing one issue using publish method:
I'm using publish method on button click, to add the item in cart:
<Button onClick={() => { PubSub.publish("ADD_TO_CART", card); }} > Add to cart </Button>

and I'm listing this in another component:
PubSub.subscribe("ADD_TO_CART", function (msg, data) { console.log(data); });
but problem is, when I clicked 3-4 times on the same button, the listener prints all previous value and new value as well. is there any way to publish only latest value not the past values??

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions