You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jscodeshift's codemod to replace React.FC when using React with Typescript
1
+
# codemod-replace-react-fc-typescript
2
+
3
+
A codemod using [jscodeshift](https://github.com/facebook/jscodeshift) to remove `React.FC` and `React.SFC` from your codebase
4
+
5
+
## Motivation
6
+
7
+
IF you use React and Typescript, you might have come across this [GitHub PR in Create React App's repo](https://github.com/facebook/create-react-app/pull/8177) about removing `React.FC` from their base template of a Typescript project.
8
+
9
+
The three main points that made me buy this was the fact that:
10
+
11
+
- There's an implicit definition of `children` - all your components will have `children` typed!
12
+
- They don't support generics
13
+
- It does not correctly work with `defaultProps`
14
+
15
+
as well as other downsides (check out the PR description for that)
16
+
17
+
Motivated by that PR, and a lot of blog posts who also shared similar conclusions (and this [ADR](https://backstage.io/docs/architecture-decisions/adrs-adr006) from Spotify's team in which they recorded the decision of removing `React.FC` from they codebase too), I wrote this little codemod that drops `React.FC` and `React.SFC` (which was also deprecated) and replaces the Props as the type of the unique argument in the component definition.
The codemod focuses in replacing the nodes but does not do styling. You might want to run Prettier or your favorite formatting tool after the code has been modified.
0 commit comments