1

Can we call a method written in js file of one component into another component which are not in the same hierarchy? Can we use Pub-Sub for this ?

Scenario: I have two components C1 and C2. I have a lightning-record-edit-form with a nested button that is used to save the changes(I need to get rid of this button and use the button in C2 component to save the form)

Thanks

3

You can use pubsub or you can use Lightning Message Service. The latter is recommended for modern use cases, although pubsub is certainly viable.

1
  • Note that AFAIK LMS is not (yet) compatible with Communities which may push you to use "pubsub". That in turn means you should note that the conventional "pubsub" implementation does not work across namespace boundaries (you cannot use it to communcate between LWCs in different namespaces).
    – Phil W
    Oct 20 '20 at 15:05

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.