A typed React component, scaffolded correctly
Every React component in a TypeScript codebase starts the same way: a props interface, a function that destructures those props, some JSX, and an export. Getting the typing right — optional props, no implicit any, the right export style — is easy to fumble. This builder emits a clean, modern stub from a name and a prop list.
How it works
The tool parses your prop lines (name: type, with a trailing ? on the name marking it optional) into a TypeScript interface ComponentNameProps. It then writes function ComponentName({ ...destructured }: ComponentNameProps) { ... }, typing props directly on the parameter rather than using React.FC. If you enable state it imports useState and adds one const [value, setValue] = useState(...) hook. The body returns a minimal JSX wrapper that renders the props so the file compiles and renders immediately. Finally it appends either export default ComponentName or a named export.
Tips and example
- Type props on the parameter, not via
React.FC, to avoid implicitchildrenand generic friction. - Mark genuinely optional props with
?; required props should stay required to catch missing data early. - Keep the stub presentational; lift data fetching into a parent or a hook for testability.
interface GreetingProps {
name: string;
excited?: boolean;
}
export default function Greeting({ name, excited }: GreetingProps) {
return <p>Hello, {name}{excited ? "!" : "."}</p>;
}