0

I have a LWC component and I am using pubsub to fire events across other LWC components. I have a use case where I need to fire the events in sequence.

Here I want to fire 'event2' event only after 'event1' is completed

fireEvent(this.pageRef, 'event1')
fireEvent(this.pageRef, 'event2');
                    

I tried using the below promise syntax also, but it's erroring out.

fireEvent(this.pageRef, 'event1').then(() => {
                        fireEvent(this.pageRef, 'event2');
                    });

Is there any way to fire the pubsub events sequentially?

1 Answer 1

0

you could call the second event from within the callback method that runs after the first event is fired, if you need information from the lwc that is calling the first event in the second event you could pass the values as a detail object associated to the event

1
  • Awesome, it worked. I am calling event 2 from the callback function of event 1.
    – sfdc07
    Dec 17, 2020 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.