Skip to content

Latest commit

 

History

History

sse-counter

Server-Sent Events - Counter

This example demonstrates how to use Server-Sent Events to create a simple counter that updates in real-time.

Preview

Open this example on CodeSandbox:

Open in CodeSandbox

Example

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.

Related Links