Ts
Tsx
Tsx
- On mount, each component subscribes and registers its state setter as a callback.
- Clicking "Notify" in Observer1 calls notify("Hello from observer1"); both Observer1 and Observer2 update and display the new message.
- The same happens when clicking in Observer2.
- On unmount, the effect cleanup in the hook unsubscribes to avoid memory leaks.
Tsx
