DEV Community

Discussion on: The simplest way to share data between two unrelated Components in react

Collapse
 
muhammadawaisshaikh profile image
Muhammad Awais

Using Rxjs Subscribers way the service will look likes:

import { Subject } from 'rxjs';

const subject = new Subject();

export const dataService = {
setData: d => subject.next(d),
clearData: () => subject.next(),
getData: () => subject.asObservable()
};