package-trendsv0.2.1 On the server
  1. package-trends
  2. Using it
  3. On the server

On the server

Fetch once where the page is built and pass it down. No visitor costs a request, and the chart is in the first paint rather than appearing a moment later.

This site does both: the chart in the HTML was drawn when the page was built, and your browser refetched it on load.

The code for what is on screen

import { fetchDownloads } from "package-trends";
import { PackageTrend } from "package-trends/react";

const data = await fetchDownloads("react", { period: "last-month" });

return <PackageTrend package="react" data={data} variant="kpi" />;

Or without React at all

import { fetchDownloads, computeTrend, sparklineSvg } from "package-trends";

const trend = computeTrend(await fetchDownloads("react"));
const svg = sparklineSvg(trend.values, { width: 200, height: 40, dot: true });

The core is the whole library and the React entry is a wrapper over it. Every chart on this site is drawn by sparklineSvg, which is the same geometry the components use — this page loads no framework at all.