Scaffold a component to house style
Matches the conventions already in the codebase instead of importing new ones.
Write a new component that looks like it was written by whoever wrote the rest of this codebase. What it should do: [BEHAVIOUR] Here are two existing components to match: [PASTE TWO EXAMPLES] Before writing, tell me what you observed: file layout, prop typing style, how state is handled, naming, how styles are applied, whether comments are used and for what. Then write the component following those observations, not your defaults. Do not introduce a library that is not already used in the examples. Do not "improve" a convention you disagree with — a component that is stylistically correct and slightly worse is more maintainable than one that is the odd file out.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
What it should do: A button that copies a given text to the clipboard and shows "Copied" for two seconds.
Two existing components
import styles from "./Badge.module.css"
type BadgeProps = {
label: string
tone?: "neutral" | "warning"
}
export function Badge({ label, tone = "neutral" }: BadgeProps) {
return <span className={`${styles.badge} ${styles[tone]}`}>{label}</span>
}
import { useState } from "react"
import styles from "./Disclosure.module.css"
type DisclosureProps = {
title: string
children: React.ReactNode
}
/** Starts closed. Remembers nothing between page loads. */
export function Disclosure({ title, children }: DisclosureProps) {
const [isOpen, setIsOpen] = useState(false)
return (
<div className={styles.disclosure}>
<button type="button" className={styles.toggle} aria-expanded={isOpen} onClick={() => setIsOpen(!isOpen)}>
{title}
</button>
{isOpen && <div className={styles.panel}>{children}</div>}
</div>
)
}
Example output
What I observed
- File layout. One component per file, a named export, no default export. React imports first, a blank line, then the component's own CSS module.
- Props. A
type, not aninterface, named after the component plusProps, declared above it. Props are destructured in the signature, with defaults there. - State.
useStatewith a boolean namedisXand a setter namedsetIsX. - Naming. Components are function declarations in PascalCase. A handler is an inline arrow on the element, even when the line runs long.
- Styles. A CSS module imported as
styles. Each element has a class named after its role. A variant is a second class looked up by prop value, as instyles[tone]. - Comments. One JSDoc line above the component, only where the behaviour is not obvious from its name.
Badgehas none. - Other.
type="button"on every button, double quotes, no semicolons.
The component
import { useEffect, useState } from "react"
import styles from "./CopyButton.module.css"
type CopyButtonProps = {
text: string
label?: string
}
/** Shows "Copied" for two seconds after a successful copy. */
export function CopyButton({ text, label = "Copy" }: CopyButtonProps) {
const [isCopied, setIsCopied] = useState(false)
useEffect(() => {
if (!isCopied) return
const timer = setTimeout(() => setIsCopied(false), 2000)
return () => clearTimeout(timer)
}, [isCopied])
return (
<button type="button" className={styles.copyButton} onClick={() => navigator.clipboard.writeText(text).then(() => setIsCopied(true))}>
{isCopied ? "Copied" : label}
</button>
)
}
If the browser refuses the copy, the button keeps its label. Neither example handles errors, so this does not either. Say if you want a failure message, and where the house puts error text [VERIFY].
More Coding & data prompts
3 of the 17 other prompts filed under Coding & data.
Check whether this statistic supports the claim
Tests the gap between what was measured and what is being asserted.
Debug a circuit from its symptoms
Narrows an electronics fault with measurements, in a safe order.
Plan a scrape that respects the source
Checks permission and rate limits before writing any code.
Generative code tools
2 tools are filed under Generative code, the same category as this prompt.
Generative code guides
1 guide is filed under Generative code, the same category as this prompt.
Bolt.new alternatives: AI app builders compared
What Bolt.new does, which tools on this index build apps the same way in the browser, which work on your own code from the editor or terminal, and how to pick.