Skip to content

Commit 09b4da4

Browse files
committed
docs: added gif showing an example of codemod running
1 parent e8d05ab commit 09b4da4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
A codemod using [jscodeshift](https://github.com/facebook/jscodeshift) to remove `React.FC` and `React.SFC` from your codebase
44

5-
## Motivation
5+
![gif animation showing how this codemod removes React.FC](https://github.com/gndelia/codemod-replace-react-fc-typescript/blob/main/example.gif?raw=true)
6+
7+
(It's recommended to run your favorite formatting tool after the codemod :wink: )
8+
9+
## :man_teacher: Motivation
610

711
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.
812

@@ -106,7 +110,7 @@ const HelloWorld = function HelloWorld(props: Props) {
106110
}
107111
```
108112

109-
## How to use
113+
## :toolbox: How to use
110114

111115
1- Install jscodeshift
112116

@@ -128,7 +132,7 @@ There are other options you can read in the jscodeshift's Readme.
128132
jscodeshift -t Path/To/Repo/transform.ts --extensions=tsx --verbose=2 <FOLDER-YOU-WANT-TO-TRANSFORM>
129133
```
130134

131-
## Notes
135+
## :notebook: Notes
132136

133137
- 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. For example, in the following code
134138

@@ -177,5 +181,6 @@ const Component = ({ title, children }: Props) => <div title={title}>{children}<
177181

178182
However, it won't compile because `children` is not part of your `Props` definition anymore. You can solve this by manually adding the type of `children` again.
179183

184+
The value that `React.FC` provides (that accepts anything you would accept in js as children) is `{ children?: ReactNode }`. I'm intentionally not automatically adding it because you can restrict it to what you only want to accept (for instance, just a string, a number, only one component, and so on), and you know better than I do what you need.
180185

181-
The value that `React.FC` provides (that accepts anything you would accept in js as children) is `{ children?: ReactNode }`. I'm intentionally not automatically adding it because you can restrict it to what you only want to accept (for instance, just a string, a number, only one component, and so on), and you know better than I do what you need.
186+
Made with ❤ by Gonzalo

example.gif

1.18 MB
Loading

0 commit comments

Comments
 (0)