useEffect(() => {
const sse = new EventSource('[YOUR_SSE_ENDPOINT_URL]',
{ withCredentials: true });
function getRealtimeData(data) {
// process the data here,
// then pass it to state to be rendered
}
sse.onmessage = e => getRealtimeData(JSON.parse(e.data));
sse.onerror = () => {
// error log here
sse.close();
}
return () => {
sse.close();
};
}, [YOUR_DEPENDENCIES_HERE]);
Created
April 8, 2023 03:39
-
-
Save sbin0819/f5fc24542c0caedad06a3229fb8c0e16 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment