Separate event type on server side

This commit is contained in:
Léo Carpentier 2022-02-15 19:22:33 +02:00
parent 2977247193
commit ddc73ad30c
2 changed files with 3 additions and 2 deletions

View File

@ -57,7 +57,8 @@ async function run() {
const stringFormat = JSON.stringify(document);
eventArray = [stringFormat, ...eventArray];
})
response.write(`event: events, data: [${[...eventArray]}]\n\n`)
response.write(`event: events \n`)
response.write(`data: [${[...eventArray]}]\n\n`)
changeStream.on("change", data => {

View File

@ -3,7 +3,7 @@ import { useSSE, SSEProvider, createCustomSource } from 'react-hooks-sse';
import './App.css';
import EventList from '../eventList/EventList.js';
function SSE() {
const SSE = () => {
const state = useSSE('events');
const [events, setEvents] = useState([]); // initialises Event state