Dev Helpers
← Back

File name inspector

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

Open this example in the interactive library

Live preview

Source code

// components/FileNameInspector.tsx

import { useState } from "react";

export default function FileNameInspector() {
  const [file, set] = useState<File | null>(null);
  return (
    <label>
      Inspect file
      <input type="file" onChange={(e) => set(e.target.files?.[0] ?? null)} />
      {file && (
        <output>
          {file.name} · {file.size} bytes
        </output>
      )}
    </label>
  );
}