Created
May 2, 2023 23:06
-
-
Save calio/527576b49d07ea34e3ef2e46bf6b9e7d 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
import React, { useState, useEffect } from 'react'; | |
import './App.css'; | |
function App() { | |
const [content, setContent] = useState(''); | |
useEffect(() => { | |
const eventSource = new EventSource('http://localhost:3001/sse'); | |
eventSource.onmessage = (event) => { | |
setContent((prevContent) => prevContent + event.data + '\n'); | |
}; | |
return () => { | |
eventSource.close(); | |
}; | |
}, []); | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<h2>Received Content:</h2> | |
<pre>{content}</pre> | |
</header> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment