Loading...
Loading...
Enforces React component structure by always separating hooks and UI into distinct files. Use this skill whenever creating, modifying, or refactoring React components, adding new features to a React app, or generating React code of any kind. Triggers on any React/TSX work including component creation, UI changes, form building, table views, page layouts, and feature implementation. Even if the user just says "add a button" or "create a page" — if it involves React, use this skill.
npx skill4agent add thodsaphonsonthiphin/workflow-daily-work react-structureComponentName/
├── ComponentName.tsx # UI only — JSX rendering, no business logic
├── useComponentName.ts # Hook — state, handlers, side effects, data fetching
├── type.ts # TypeScript types and interfaces for this component
└── componentSlice.ts # Redux slice (only if this component owns Redux state)sxstyled()useStateuseEffectuseSelectoruseDispatch// UserList.tsx
import { useUserList } from './useUserList';
import { DataGridPremium } from '@mui/x-data-grid-premium';
export const UserList = () => {
const { rows, columns, loading, handleRowClick } = useUserList();
return (
<DataGridPremium
rows={rows}
columns={columns}
loading={loading}
onRowClick={handleRowClick}
/>
);
};useStateuseEffectuseMemouseCallbackuseSelectoruseDispatch// useUserList.ts
import { useSelector, useDispatch } from 'react-redux';
import { GridColDef, GridRowParams } from '@mui/x-data-grid-premium';
import { selectUsers, fetchUsers } from './userSlice';
import { User } from './type';
export const useUserList = () => {
const dispatch = useDispatch();
const users = useSelector(selectUsers);
const [loading, setLoading] = useState(true);
useEffect(() => {
dispatch(fetchUsers()).finally(() => setLoading(false));
}, [dispatch]);
const columns: GridColDef<User>[] = useMemo(() => [
{ field: 'name', headerName: 'Name', flex: 1 },
{ field: 'email', headerName: 'Email', flex: 1 },
], []);
const handleRowClick = useCallback((params: GridRowParams<User>) => {
// handle row click
}, []);
return { rows: users, columns, loading, handleRowClick };
};// type.ts
export interface User {
id: string;
name: string;
email: string;
}
export interface UserListProps {
filterByRole?: string;
}createSlicecreateAsyncThunksxstyled()@mui/x-data-grid-premiumDataGridPremiumTableflowchart TD
A[User clicks delete button] --> B[UserList.tsx calls handleDelete]
B --> C[useUserList.ts handleDelete]
C --> D[dispatch deleteUser thunk]
D --> E[userSlice.ts async thunk → API call]
E --> F[userSlice reducer updates state]
F --> G[useSelector picks up new state]
G --> H[UserList.tsx re-renders without deleted row]useComponentName.tstype.tsComponentName.tsxcomponentSlice.ts