Skip to main content
Codegen SDK provides powerful APIs for modernizing React codebases. This guide will walk you through common React modernization patterns. Common use cases include:
  • Upgrading to modern APIs, including React 18+
  • Automatically memoizing components
  • Converting to modern hooks
  • Standardizing prop types
  • Organizing components into individual files
and much more.

Converting Class Components to Functions

Here’s how to convert React class components to functional components:

Migrating to Modern Hooks

Convert legacy patterns to modern React hooks:

Standardizing Props

Inferring Props from Usage

Add proper prop types and TypeScript interfaces based on how props are used:

Extracting Inline Props

Convert inline prop type definitions to separate type declarations:
This will convert components from:
To:
Extracting prop types makes them reusable and easier to maintain. It also improves code readability by separating type definitions from component logic.

Updating Fragment Syntax

Modernize React Fragment syntax:

Organizing Components into Individual Files

A common modernization task is splitting files with multiple components into a more maintainable structure where each component has its own file. This is especially useful when modernizing legacy React codebases that might have grown organically.
This script will:
  1. Find files containing multiple React components
  2. Create a new directory structure based on the original file
  3. Move each non-default exported component to its own file
  4. Preserve imports and dependencies automatically
  5. Keep default exports in their original location
For example, given this structure:
It will create:
The strategy="add_back_edge" parameter ensures that any components that were previously co-located can still import each other without circular dependencies. Learn more about moving code here.