DEV Community

Cover image for React + fetchstream-js: Render JSON as It Arrives
CODING IN BLOOD
CODING IN BLOOD

Posted on

React + fetchstream-js: Render JSON as It Arrives

Most React apps still wait for the full JSON response before showing anything. That means a loading spinner, a blank table, and slower perceived performance. fetchstream-js solves this by parsing JSON progressively, so your UI can update as data arrives.

Install

npm install fetchstream-js
Enter fullscreen mode Exit fullscreen mode

Basic React example

import { useEffect, useState } from "react";
import { fetchStream } from "fetchstream-js";

export default function Users() {
  const [snap, setSnap] = useState({ data: null, chunks: 0, done: false });

  useEffect(() => {
    fetchStream("/api/users")
      .live(({ data, chunks, done }) => {
      setSnap({ data, chunks, done });
      })
      .catch(console.error);
  }, []);

  return (
    <div>
      <h2>Users</h2>
      <pre>{JSON.stringify(snap.data, null, 2)}</pre>
      <p>{snap.chunks} chunks received {snap.done ? "• done" : ""}</p>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Why this works well in React

With fetchstream-js, your component does not need to wait for the entire payload. The UI can render partial data early, which improves perceived performance and makes the app feel faster.

When to use it

Use fetchstream-js for:

  • large JSON lists
  • dashboards
  • tables
  • any UI where early feedback matters

Final thought

If your React app spends too long on a spinner, fetchstream-js is a simple upgrade. One install, one hook, and your UI starts showing data sooner.

🔗 Links

Top comments (0)