Dev Helpers
← Back

Plain text download link

Import and render <PlainTextDownloadLink /> in a React project.

Open this example in the interactive library

Live preview

Source code

// 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>
  );
}