Skip to content

Commit bb96306

Browse files
Add codemods to upgrade guide (#6897)
* Add codemods to upgrade guide * Update src/content/blog/2024/04/25/react-19-upgrade-guide.md Co-authored-by: Ahmed Abdelbaset <[email protected]> * Add benefits --------- Co-authored-by: Ahmed Abdelbaset <[email protected]>
1 parent f055f8f commit bb96306

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

src/content/blog/2024/04/25/react-19-upgrade-guide.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ For a list of changes in 18.3 see the [Release Notes](https://github.com/faceboo
3939
In this post, we will guide you through the steps for upgrading libraries to React 19 beta:
4040

4141
- [Installing](#installing)
42+
- [Codemods](#codemods)
4243
- [Breaking changes](#breaking-changes)
4344
- [New deprecations](#new-deprecations)
4445
- [Notable changes](#notable-changes)
@@ -97,6 +98,37 @@ If you're using TypeScript, you also need to update the types. Once React 19 is
9798

9899
We're also including a codemod for the most common replacements. See [TypeScript changes](#typescript-changes) below.
99100

101+
## Codemods {/*codemods*/}
102+
103+
To help with the upgrade, we've worked with the team at [codemod.com](https://codemod.com) to publish codemods that will automatically update your code to many of the new APIs and patterns in React 19.
104+
105+
All codemods are available in the [`react-codemod` repo](https://github.com/reactjs/react-codemod) and the Codemod team have joined in helping maintain the codemods. To run these codemods, we recommend using the `codemod` command instead of the `react-codemod` because it runs faster, handles more complex code migrations, and provides better support for TypeScript.
106+
107+
108+
<Note>
109+
110+
#### Run all React 19 codemods {/*run-all-react-19-codemods*/}
111+
112+
Run all codemods listed in this guide with the React 19 `codemod` recipe:
113+
114+
```bash
115+
npx codemod@latest react/19/migration-recipe
116+
```
117+
118+
This will run the following codemods from `react-codemod`:
119+
- [`replace-reactdom-render`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-reactdom-render)
120+
- [`replace-string-ref`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-string-ref)
121+
- [`replace-act-import`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-act-import)
122+
- [`replace-use-form-state`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-use-form-state)
123+
- [`prop-types-typescript`](TODO)
124+
125+
This does not include the TypeScript changes. See [TypeScript changes](#typescript-changes) below.
126+
127+
</Note>
128+
129+
Changes that include a codemod include the command below.
130+
131+
For a list of all available codemods, see the [`react-codemod` repo](https://github.com/reactjs/react-codemod).
100132

101133
## Breaking changes {/*breaking-changes*/}
102134

@@ -128,7 +160,7 @@ For more info, see the docs for [`createRoot`](https://react.dev/reference/react
128160
### Removed deprecated React APIs {/*removed-deprecated-react-apis*/}
129161

130162
#### Removed: `propTypes` and `defaultProps` for functions {/*removed-proptypes-and-defaultprops*/}
131-
`PropTypes` were deprecated in [April 2017 (v15.5.0)](https://legacy.reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings).
163+
`PropTypes` were deprecated in [April 2017 (v15.5.0)](https://legacy.reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings).
132164

133165
In React 19, we're removing the `propType` checks from the React package, and using them will be silently ignored. If you're using `propTypes`, we recommend migrating to TypeScript or another type-checking solution.
134166

@@ -158,6 +190,16 @@ function Heading({text = 'Hello, world!'}: Props) {
158190
}
159191
```
160192

193+
<Note>
194+
195+
Codemod `propTypes` to TypeScript with:
196+
197+
```bash
198+
npx codemod@latest react/prop-types-typescript
199+
```
200+
201+
</Note>
202+
161203
#### Removed: Legacy Context using `contextTypes` and `getChildContext` {/*removed-removing-legacy-context*/}
162204

163205
Legacy Context was deprecated in [October 2018 (v16.6.0)](https://legacy.reactjs.org/blog/2018/10/23/react-v-16-6.html).
@@ -253,7 +295,11 @@ class MyComponent extends React.Component {
253295

254296
<Note>
255297

256-
To help with the migration, we will be publishing a [react-codemod](https://github.com/reactjs/react-codemod/#string-refs) to automatically replace string refs with `ref` callbacks. Follow [this PR](https://github.com/reactjs/react-codemod/pull/309) for updates and to try it out.
298+
Codemod string refs with `ref` callbacks:
299+
300+
```bash
301+
npx codemod@latest react/19/replace-string-ref
302+
```
257303

258304
</Note>
259305

@@ -340,6 +386,16 @@ All other `test-utils` functions have been removed. These utilities were uncommo
340386

341387
See the [warning page](https://react.dev/warnings/react-dom-test-utils) for alternatives.
342388

389+
<Note>
390+
391+
Codemod `ReactDOMTestUtils.act` to `React.act`:
392+
393+
```bash
394+
npx codemod@latest react/19/replace-act-import
395+
```
396+
397+
</Note>
398+
343399
#### Removed: `ReactDOM.render` {/*removed-reactdom-render*/}
344400

345401
`ReactDOM.render` was deprecated in [March 2022 (v18.0.0)](https://react.dev/blog/2022/03/08/react-18-upgrade-guide). In React 19, we're removing `ReactDOM.render` and you'll need to migrate to using [`ReactDOM.createRoot`](https://react.dev/reference/react-dom/client/createRoot):
@@ -355,6 +411,16 @@ const root = createRoot(document.getElementById('root'));
355411
root.render(<App />);
356412
```
357413

414+
<Note>
415+
416+
Codemod `ReactDOM.render` to `ReactDOM.createRoot`:
417+
418+
```bash
419+
npx codemod@latest react/19/replace-reactdom-render
420+
```
421+
422+
</Note>
423+
358424
#### Removed: `ReactDOM.hydrate` {/*removed-reactdom-hydrate*/}
359425

360426
`ReactDOM.hydrate` was deprecated in [March 2022 (v18.0.0)](https://react.dev/blog/2022/03/08/react-18-upgrade-guide). In React 19, we're removing `ReactDOM.hydrate` you'll need to migrate to using [`ReactDOM.hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot),

0 commit comments

Comments
 (0)