Until @neat patrol comes by, see if this example works for you.
https://github.com/remix-run/examples/tree/main/_official-realtime-app
#Server sent events with remix
1 messages · Page 1 of 1 (latest)
Hello @wild sapphire I tried this solution but unfortunately it doesn't work.😔
Remix version?
version : 1.8.2
`const { notificationsData } = useLoaderData<typeof loader>()
const [notifications, setNotifications] = React.useState<Notification[]>(
notificationsData as any,
)
React.useEffect(() => {
const url = new URL('http://localhost:3000/graphql')
url.searchParams.set(
'query',
`subscription NotificationCreated {
notificationCreated {
id
content
createdAt
updatedAt
} }`,
)
const evtSource = new EventSource(url, { withCredentials: true })
evtSource.onmessage = (event) => {
const data = JSON.parse(event.data)
.data as NotificationCreatedSubscription
setNotifications((prev: any) => [data.notificationCreated, ...prev])
}
return () => evtSource.close()
}, [])`