Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Standardized guidelines and patterns for Frontend React Component Composition.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 26% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 5% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 36% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 36% | 0% |
Basic Children
typescriptinterface ContainerProps { children: React.ReactNode; } export const Container = ({ children }: ContainerProps) => { return <div className="container">{children}</div>; };
Typed Children
typescriptimport { ReactElement } from 'react'; interface TabsProps { children: ReactElement<TabProps> | ReactElement<TabProps>[]; } export const Tabs = ({ children }: TabsProps) => { const tabs = React.Children.toArray(children); return <div>{tabs}</div>; };
typescriptinterface MouseTrackerProps { render: (position: { x: number; y: number }) => React.ReactNode; } export function MouseTracker({ render }: MouseTrackerProps) { const [position, setPosition] = useState({ x: 0, y: 0 }); useEffect(() => { const handleMove = (e: MouseEvent) => { setPosition({ x: e.clientX, y: e.clientY }); }; window.addEventListener('mousemove', handleMove); return () => window.removeEventListener('mousemove', handleMove); }, []); return <>{render(position)}</>; } // Usage <MouseTracker render={({ x, y }) => ( <div>Mouse at {x}, {y}</div> )} />
typescriptimport { createContext, useContext, useState } from 'react'; // Context for internal state interface TabsContextValue { activeTab: string; setActiveTab: (id: string) => void; } const TabsContext = createContext<TabsContextValue | null>(null); export const Tabs = ({ children }: { children: React.ReactNode }) => { const [activeTab, setActiveTab] = useState(''); return ( <TabsContext.Provider value={{ activeTab, setActiveTab }}> <div className="tabs">{children}</div> </TabsContext.Provider> ); }; Tabs.List = ({ children }: { children: React.ReactNode }) => { return <div className="tab-list">{children}</div>; }; Tabs.Tab = ({ id, children }: { id: string; children: React.ReactNode }) => { const context = useContext(TabsContext); if (!context) throw new Error('Tab must be used within Tabs'); return ( <button className={context.activeTab === id ? 'active' : ''} onClick={() => context.setActiveTab(id)} > {children} </button> ); }; Tabs.Panel = ({ id, children }: { id: string; children: React.ReactNode }) => { const context = useContext(TabsContext); if (!context) throw new Error('Panel must be used within Tabs'); return context.activeTab === id ? <div>{children}</div> : null; }; // Usage <Tabs> <Tabs.List> <Tabs.Tab id="home">Home</Tabs.Tab> <Tabs.Tab id="profile">Profile</Tabs.Tab> </Tabs.List> <Tabs.Panel id="home">Home Content</Tabs.Panel> <Tabs.Panel id="profile">Profile Content</Tabs.Panel> </Tabs>
typescriptinterface LayoutProps { header?: React.ReactNode; sidebar?: React.ReactNode; content: React.ReactNode; footer?: React.ReactNode; } export const Layout = ({ header, sidebar, content, footer }: LayoutProps) => { return ( <div className="layout"> {header && <header>{header}</header>} <div className="main"> {sidebar && <aside>{sidebar}</aside>} <main>{content}</main> </div> {footer && <footer>{footer}</footer>} </div> ); }; // Usage <Layout header={<Header />} sidebar={<Nav />} content={<Article />} footer={<Footer />} />
typescriptfunction withLoading<P extends object>( Component: React.ComponentType<P> ) { return function WithLoadingComponent( props: P & { loading: boolean } ) { if (props.loading) { return <div>Loading...</div>; } return <Component {...props} />; }; } // Usage const UserProfileWithLoading = withLoading(UserProfile); <UserProfileWithLoading user={user} loading={isLoading} />
typescriptinterface InputProps { label: string; error?: string; } export const Input = forwardRef<HTMLInputElement, InputProps>( ({ label, error, ...props }, ref) => { return ( <div> <label>{label}</label> <input ref={ref} {...props} /> {error && <span className="error">{error}</span>} </div> ); } ); Input.displayName = 'Input';
Other measured skills in the registry, with their headline benchmark lift.