Created
January 27, 2021 15:43
-
-
Save luistak/5b761d11c36476eb99085e759954f9e3 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
function App() { | |
const [messages, setMessages] = useState([]); | |
const handleNewMessage = (event) => { | |
setMessages((currentMessages) => currentMessages.concat(event.detail)); | |
}; | |
useEffect(() => { | |
window.addEventListener('message', handleNewMessage); | |
return () => { | |
window.removeEventListener('message', handleNewMessage) | |
} | |
}, [handleNewMessage]); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment