Dev Helpers

React / Files and downloads

Plain text download link

Dev Helpers · December 13, 2025

A text download needs an appropriate filename and MIME type. Use the same content source for the on-screen preview and exported file.

Worked example

// components/PlainTextDownloadLink.tsx

export default function PlainTextDownloadLink({
  filename = "notes.txt",
  text = "Studio notes",
}: { filename?: string; text?: string } = {}) {
  return (
    <a
      download={filename}
      href={"data:text/plain;charset=utf-8," + encodeURIComponent(text)}
    >
      Download {filename}
    </a>
  );
}

Implementation notes

Revoke object URLs that outlive their export interaction. Repeated downloads in a long-running application can otherwise retain unnecessary resources.

Try it yourself

Include non-ASCII text and inspect the downloaded document.

Open the React example →

Editorial date December 13, 2025 · Published December 6, 2026

Related articles

Percentage meter

A percentage meter needs both a bounded visual fill and a meaningful textual value. Handle a zero denominator before dividing.

Vertical typesetting sample

Vertical typesetting changes the reading direction and available inline space. Treat the sample text as content so it remains selectable and accessible.

Square cover crop

A square image crop gives a card grid consistent geometry. The crop anchor determines whether the most important part of a photo survives.