mirror of
https://github.com/khairul169/code-share.git
synced 2026-10-24 11:53:58 +07:00
feat: add sandbox
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const useSSE = (url: string, onData: (data: any) => void) => {
|
||||
useEffect(() => {
|
||||
const sse = new EventSource(url, { withCredentials: true });
|
||||
|
||||
sse.onmessage = (e) => {
|
||||
onData(JSON.parse(e.data));
|
||||
};
|
||||
|
||||
sse.onerror = () => {
|
||||
console.log("err!");
|
||||
sse.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
sse.close();
|
||||
};
|
||||
}, [url]);
|
||||
};
|
||||
Reference in New Issue
Block a user