Instruction file imported from susuwatari15/ponie-tools (
.github/instructions/react-components.instructions.md). Copyright stays with the author.
React Component Guidelines
Component Structure
import type { FC } from "react";
type MyComponentProps = {
m: SomeController;
className?: string;
};
export const MyComponent: FC<MyComponentProps> = ({ m, className = "" }) => {
return (
<div className={`base-classes ${className}`}>
{/* content */}
</div>
);
};
Rules
- Always use
typeimports for types:import type { FC } from "react" - Annotate components with
FCtype - Use named exports for components; use default exports only for
page.tsxandlayout.tsx - Props types defined inline above the component as
type(notinterface) - Accept
className?: stringprop for composability - Use tabs for indentation, double quotes for strings
- Use
@/*path alias for imports fromsrc/
Client Components
Pages with interactivity must have "use client" at the top:
"use client";
import type { FC } from "react";
// ...
Components using useSearchParams() must be wrapped in <Suspense> boundaries.
Controller Hook Pattern
Each feature page has a controller hook that owns all state:
// _hooks/useMyFeature.ts
export function useMyFeature() {
const [value, setValue] = useState("");
// ... all state and handlers
return { value, setValue, /* ... */ };
}
export type MyFeatureController = ReturnType<typeof useMyFeature>;
Page component creates the controller and passes it as m prop:
// page.tsx
"use client";
import type { FC } from "react";
const MyFeaturePage: FC = () => {
const m = useMyFeature();
return <MyFeatureView m={m} />;
};
export default MyFeaturePage;
Child components receive m (or destructured parts) as props:
type Props = { m: MyFeatureController };
export const MyFeatureView: FC<Props> = ({ m }) => { /* ... */ };
Imports Order
"use client"directive (if needed)- React / type imports
- Next.js imports (
next/navigation,next/image, etc.) - Third-party libraries
- Shared components (
@/components/) - Shared lib/types (
@/lib/,@/types/) - Feature-local components (
./_components/) - Feature hooks, styles, types, lib