Skip to content

Instantly share code, notes, and snippets.

@luistak
Created January 27, 2021 15:46
Show Gist options
  • Save luistak/277a2d26e68a0d4d9579c36e81537e2d to your computer and use it in GitHub Desktop.
Save luistak/277a2d26e68a0d4d9579c36e81537e2d to your computer and use it in GitHub Desktop.
const { worky } = window;
function App() {
const [messages, setMessages] = useState([]);
const handleNewMessage = (message) => {
if (message.data.type) {
return;
}
setMessages((currentMessages) => currentMessages.concat(message.data));
};
useEffect(() => {
worky.addEventListener('message', handleNewMessage);
return () => {
worky.removeEventListener('message', handleNewMessage)
}
}, [handleNewMessage]);
return (
<div className="MF">
<h3>Microfrontend 1️⃣</h3>
<p>New messages will be displayed below 👇</p>
<div className="MF__messages">
{messages.map((something, i) => <p key={something + i}>{something}</p>)}
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment