Open this example in the interactive library
Live preview
Source code
// components/PerimeterWithGate.tsx
import { useState } from "react";
export default function PerimeterWithGate({
width = 12,
height = 8,
}: { width?: number; height?: number } = {}) {
const [gate, set] = useState(1);
return (
<label>
Gate width
<input
type="range"
max={width}
value={gate}
onChange={(e) => set(+e.target.value)}
/>
<output>{2 * (width + height) - gate} units of fencing</output>
</label>
);
}
