Skip to content

codemod/react-codemod

Repository files navigation

React Codemods

This repository contains the public JSSG codemods for React migrations and cleanup work.

All codemods are free and open source, with the source code available in this repository.

Usage

npx codemod <codemod-name> --target <path>
  • <codemod-name> — name of the codemod (see available codemods below)
  • <path> — files or directory to transform

Check Codemod docs for the full list of available commands.

Available Codemods

All React codemods are also available in the Codemod Registry.

react-19-migration-recipe

Runs all React 19 migration codemods in sequence.

npx codemod react-19-migration-recipe --target <path>

See react-19-migration-recipe.

react-19-use-context-hook

Replaces usages of React.useContext(...) with React.use(...).

npx codemod react-19-use-context-hook --target <path>

See react-19-use-context-hook.

react-19-replace-act-import

Updates act import path from react-dom/test-utils to react.

npx codemod react-19-replace-act-import --target <path>

See react-19-replace-act-import.

react-19-replace-string-ref

Replaces deprecated string refs with callback refs.

npx codemod react-19-replace-string-ref --target <path>

See react-19-replace-string-ref.

react-19-replace-use-form-state

Replaces usages of useFormState() with useActionState().

npx codemod react-19-replace-use-form-state --target <path>

See react-19-replace-use-form-state.

react-19-replace-reactdom-render

Replaces usages of ReactDOM.render() with createRoot(node).render().

npx codemod react-19-replace-reactdom-render --target <path>

See react-19-replace-reactdom-render.

react-proptypes-to-prop-types

Replaces React.PropTypes references with the prop-types package and adds the appropriate import statement.

npx codemod react-proptypes-to-prop-types --target <path>

See react-proptypes-to-prop-types.

Additional useful React codemods

Development

pnpm install
pnpm run ci

Run tests:

pnpm test

Run type checking:

pnpm run check-types

Support and Contributing

If you want to contribute, see CONTRIBUTING.md.

About

React codemods

Topics

Resources

Contributing

Stars

Watchers

Forks

Contributors