Open this example in the interactive library
Live preview
Source code
// components/WordCountEditor.tsx
import { useState } from "react";
export default function WordCountEditor({
label = "Project notes",
}: { label?: string } = {}) {
const [value, set] = useState("");
return (
<label>
{label}
<textarea value={value} onChange={(e) => set(e.target.value)} />
<output>{value.trim() ? value.trim().split(/\s+/).length : 0} words</output>
</label>
);
}
