Apply, review, and explain React conventions from the TypeScript Style Guide. Use automatically for TypeScript and TSX tasks involving prop-derived state, prop typing, component responsibilities, data flow, compound components, or client and server state.
Use typescript-react to review one TSX component I provide. Inspect the repository's React conventions first. Check whether state initialized from props is justified, whether intentional initial-value props should use the initial prefix, and whether child components receive only necessary props. Give a short explanation and one focused suggested change, leaving files unchanged.
Required inputs
One TSX component, supplied as code or an existing file path, plus relevant child component interfaces.
The intended behavior when the component's props change.
Access to the repository's React and framework conventions.
Suggested template by Skill Leaderboard, grounded in the linked source. Task evidence ↗
SKILL.md
name: typescript-reactdescription: Apply, review, and explain React conventions from the TypeScript Style Guide. Use automatically for TypeScript and TSX tasks involving prop-derived state, prop typing, component responsibilities, data flow, compound components, or client and server state.
React
Apply the TypeScript Style Guide's React conventions in the context of the current task.
Workflow
Inspect the consuming repository's React, framework, and state-management conventions.
Let explicit repository conventions take precedence over this opinionated guidance.
Apply, review, or explain only the guidance relevant to the task.
State important tradeoffs when component or state design depends on application context.
Boundaries
Keep TypeScript, React, and ESLint responsible for checks they can enforce automatically.
Do not redesign unrelated components or state merely because this skill is active.
Related Guidance
Functions
For detailed function design guidance, use typescript-functions when it is available.
Appendix - React
Since React components and hooks are also functions, the respective function conventions apply.
Props To State
In general, avoid using props as initial state because the state will not update when the props change. This can lead to bugs that are hard to track, unintended side effects, and difficulty testing.
When there is truly a use case for using a prop as initial state, the prop must be prefixed with initial (e.g. initialProduct, initialSort etc.)
// ❌ Avoid using props to state
type FooProps = {
productName: string;
userId: string;
};
export const Foo = ({ productName, userId }: FooProps) => {
const [productName, setProductName] = useState(productName);
...
// ✅ Use prop prefix `initial` when there is a rationale for it
type FooProps = {
initialProductName: string;
userId: string;
};
export const Foo = ({ initialProductName, userId }: FooProps) => {
const [productName, setProductName] = useState(initialProductName);
...
Props Type
// ❌ Avoid using React.FC type
type FooProps = {
name: string;
score: number;
};
export const Foo: React.FC<FooProps> = ({ name, score }) => {
// ✅ Use props argument with type
type FooProps = {
name: string;
score: number;
};
export const Foo = ({ name, score }: FooProps) => {...
Component Types
Container
All container components have the suffix "Container" or "Page" [ComponentName]Container|Page. Use the "Page" suffix to indicate that a component is an actual web page.
Each feature has a container component (AddUserContainer.tsx, EditProductContainer.tsx, ProductsPage.tsx etc.)
Pass only the necessary props to child components rather than passing the entire object.
Utilize storing state in the URL, especially for filtering, sorting etc.
Don't sync URL state with local state.
Consider passing data simply through props, using the URL, or composing children. Use global state (Zustand, Context) as a last resort.
Use React compound components when components should belong and work together: menu, accordion, navigation, tabs, list, etc.
Always export compound components as:
UI components should show derived state and send events, nothing more (no business logic).
As in many programming languages, function arguments can be passed to the next function and on to the next etc.
React components are no different, so prop drilling should not become an issue.
If prop drilling truly becomes an issue as the app scales, try refactoring render methods or local state in parent components, or use composition.
Data fetching is only allowed in container components.
Use of client-state library for global state is discouraged.
Reconsider whether something should be truly global across the application, e.g. themeMode or Permissions, or whether it can be put in server state (e.g. user settings from the /me endpoint). If global state is still truly needed, use Zustand or Context.
typescript-react by mkosir · The Skill Leaderboard