Coding task · JavaScript and React course · Module 10: React Ecosystem and Future
Practice: Micro-frontends
Micro-frontends should not import each other: they communicate through events (an Event Bus or a CustomEvent on window). A subscriber registers in useEffect and unsubscribes in the cleanup, which React calls on unmount and before running the effect again. In development StrictMode runs the effect twice, so a missing cleanup doubles the events right away.
Task
Connect two independent micro-frontends with an event bus: the parts catalogue (team Astro MFE) sends the cargo:add event, and the cargo hold (team Commander Nova MFE) receives it. ___BLANK1___: the function returned by on() removes only this one subscription (use the off method with the same event and handler). ___BLANK2___: emit calls every stored function with the event data (payload). ___BLANK3___: the effect in CargoHold returns a function that removes the subscription, so that no orphaned listener stays after hiding the cargo hold (and the double effect in StrictMode does not add parts twice).