Open this example in the interactive library
Live preview
Source code
// components/ClickToLoadPhotograph.tsx
import { useState } from "react";
export default function ClickToLoadPhotograph({
src = "/studio.jpg",
caption = "Inside the studio",
}: { src?: string; caption?: string } = {}) {
const [loaded, set] = useState(false);
return loaded ? (
<img alt={caption} src={src} style={{ maxWidth: "100%" }} />
) : (
<button onClick={() => set(true)}>Load photo: {caption}</button>
);
}
