All skills
wshobson avatar

/react-modernization

@be57c0b
by Seth Hobsonwshobson/agents40k stars
4,281

Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.

Use this Skill: https://skilld.dev/gh/wshobson/agents/react-modernization

This session only. Nothing lands on disk.

referencesdetails.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

react-modernization — additional patterns and templates

Codemods for Automation

Run React Codemods

# Rename unsafe lifecycle methods
npx jscodeshift -t https://raw.githubusercontent.com/reactjs/react-codemod/master/transforms/rename-unsafe-lifecycles.js src/

# Update React imports (React 17+)
npx jscodeshift -t https://raw.githubusercontent.com/reactjs/react-codemod/master/transforms/update-react-imports.js src/

# Add error boundaries
npx jscodeshift -t https://raw.githubusercontent.com/reactjs/react-codemod/master/transforms/error-boundaries.js src/

# For TypeScript files
npx jscodeshift -t https://raw.githubusercontent.com/reactjs/react-codemod/master/transforms/rename-unsafe-lifecycles.js --parser=tsx src/

# Dry run to preview changes
npx jscodeshift -t https://raw.githubusercontent.com/reactjs/react-codemod/master/transforms/rename-unsafe-lifecycles.js --dry --print src/

# Class to Hooks (third-party)
npx codemod react/hooks/convert-class-to-function src/

Custom Codemod Example

// custom-codemod.js
module.exports = function (file, api) {
  const j = api.jscodeshift;
  const root = j(file.source);

  // Find setState calls
  root
    .find(j.CallExpression, {
      callee: {
        type: "MemberExpression",
        property: { name: "setState" },
      },
    })
    .forEach((path) => {
      // Transform to useState
      // ... transformation logic
    });

  return root.toSource();
};

// Run: jscodeshift -t custom-codemod.js src/

Performance Optimization

useMemo and useCallback

function ExpensiveComponent({ items, filter }) {
  // Memoize expensive calculation
  const filteredItems = useMemo(() => {
    return items.filter((item) => item.category === filter);
  }, [items, filter]);

  // Memoize callback to prevent child re-renders
  const handleClick = useCallback((id) => {
    console.log("Clicked:", id);
  }, []); // No dependencies, never changes

  return <List items={filteredItems} onClick={handleClick} />;
}

// Child component with memo
const List = React.memo(({ items, onClick }) => {
  return items.map((item) => (
    <Item key={item.id} item={item} onClick={onClick} />
  ));
});

Code Splitting

import { lazy, Suspense } from "react";

// Lazy load components
const Dashboard = lazy(() => import("./Dashboard"));
const Settings = lazy(() => import("./Settings"));

function App() {
  return (
    <Suspense fallback={<Loading />}>
      <Routes>
        <Route path="/dashboard" element={<Dashboard />} />
        <Route path="/settings" element={<Settings />} />
      </Routes>
    </Suspense>
  );
}

TypeScript Migration

// Before: JavaScript
function Button({ onClick, children }) {
  return <button onClick={onClick}>{children}</button>;
}

// After: TypeScript
interface ButtonProps {
  onClick: () => void;
  children: React.ReactNode;
}

function Button({ onClick, children }: ButtonProps) {
  return <button onClick={onClick}>{children}</button>;
}

// Generic components
interface ListProps<T> {
  items: T[];
  renderItem: (item: T) => React.ReactNode;
}

function List<T>({ items, renderItem }: ListProps<T>) {
  return <>{items.map(renderItem)}</>;
}

Migration Checklist

### Pre-Migration

- [ ] Update dependencies incrementally (not all at once)
- [ ] Review breaking changes in release notes
- [ ] Set up testing suite
- [ ] Create feature branch

### Class → Hooks Migration

- [ ] Identify class components to migrate
- [ ] Start with leaf components (no children)
- [ ] Convert state to useState
- [ ] Convert lifecycle to useEffect
- [ ] Convert context to useContext
- [ ] Extract custom hooks
- [ ] Test thoroughly

### React 18 Upgrade

- [ ] Update to React 17 first (if needed)
- [ ] Update react and react-dom to 18
- [ ] Update @types/react if using TypeScript
- [ ] Change to createRoot API
- [ ] Test with StrictMode (double invocation)
- [ ] Address concurrent rendering issues
- [ ] Adopt Suspense/Transitions where beneficial

### Performance

- [ ] Identify performance bottlenecks
- [ ] Add React.memo where appropriate
- [ ] Use useMemo/useCallback for expensive operations
- [ ] Implement code splitting
- [ ] Optimize re-renders

### Testing

- [ ] Update test utilities (React Testing Library)
- [ ] Test with React 18 features
- [ ] Check for warnings in console
- [ ] Performance testing

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides comprehensive instructions and examples for upgrading React applications and migrating to modern hooks-based patterns. It includes commands to run official React transformation scripts from the official React repository. No security issues were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1 file scanned · No issues

  • ZeroLeaks5mo

    2 findings · Score: 80/100

Signed by skilld at be57c0b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago
  • React
  • TypeScript
  • hooks
  • class-components
  • react-18
  • concurrent-rendering
  • migrations
  • suspense
  • codemods
  • state-management

README badge

README badge for wshobson/agents/react-modernization

Automates React version upgrades, class-to-hooks migration, and adoption of React 18 concurrent features through codemod patterns and lifecycle transformations. Targets teams modernizing legacy React codebases, including state management refactoring, JSX transform updates, and Suspense integration.

Generated from the current SKILL.md.

Does this skill cover migrating from class components to hooks?
Yes. The skill includes patterns for converting class state and lifecycle methods to useState and useEffect hooks, as well as replacing higher-order components and Context consumers with custom hooks and useContext.
What React versions does this skill address?
The skill covers upgrade paths from React 16 through 18, including breaking changes in React 17 (event delegation, JSX transform) and React 18 (automatic batching, concurrent rendering, new root API).
Does this skill include guidance on React 18 concurrent features?
Yes. It covers the new createRoot API, automatic batching, useTransition for non-urgent updates, and Suspense for data fetching.
Can this skill help with TypeScript migrations?
The skill mentions updating to TypeScript as a use case but does not provide detailed TypeScript-specific patterns or guidance.
Are codemods included for automated refactoring?
The skill description mentions codemods for automated transformation as a topic, but the SKILL.md content does not include codemod implementations or scripts.

Generated from the current SKILL.md. These answers refresh after source changes.