Created
January 27, 2021 15:46
-
-
Save luistak/277a2d26e68a0d4d9579c36e81537e2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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