This example demonstrates how to use Server-Sent Events to create a simple counter that updates in real-time.
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 starts an interval that emits a new message every second with the current time formatted in English.
Client-side, the useEventSource
hook from Remix Utils is used to subscribe to the SSE endpoint and display the new date.