This example demonstrates how to use Server-Sent Events to create a simple chat app without persistant storage.
Open this example on CodeSandbox:
The example uses the eventStream
response helper from Remix Utils to implement a SSE endpoint.
In that endpoint the server subscribe to an EventEmitter to get new messages and broadcast them to subscribers.
Client-side, the useEventSource
hook from Remix Utils is used to subscribe to the SSE endpoint and display new messages as they arrive.
All paired with a Remix form to send new messages to an action which are then emitted to the EventEmitter.