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
- 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.
114
-
- If your component was using the implicit definition of `children` provided by `React.FC`, you will have to add the explicit definition or the code won't compile. The value that `React.FC` provides (that accepts anything you would accept in js as children) is `{ children?: ReactNode }`, but you can restrict it to what you only want to accept (for instance, just a string, a number, only one component, and so on)
113
+
- 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
114
+
115
+
```tsx
116
+
importReactfrom'react'
117
+
118
+
interfaceProps { id:number, text:string }
119
+
const Component:React.FC<Props> = (props) => (
120
+
<div>
121
+
<span>{props.id}</span>
122
+
</div>
123
+
)
124
+
```
125
+
126
+
after running the codemod, you might lose the parenthesis
127
+
128
+
```tsx
129
+
importReactfrom'react'
130
+
131
+
interfaceProps { id:number, text:string }
132
+
const Component = (props:Props) => <div>
133
+
<span>{props.id}</span>
134
+
</div>
135
+
```
136
+
137
+
this is because those parenthesis are not strictly required for the code to work. You can fix this by running `Prettier` (or whatever tool you're using to format your code) easily, as the code is still valid
138
+
139
+
140
+
141
+
- If your component was using the implicit definition of `children` provided by `React.FC`, you will have to add the explicit definition or the code won't compile. For example, the following code
142
+
143
+
```tsx
144
+
importReactfrom'react'
145
+
146
+
typeProps= { title:string }
147
+
const Component:React.FC<Props> = ({ title, children }) => <divtitle={title}>{children}</div>
148
+
```
149
+
150
+
will be transformed into this after running the codemod
151
+
```tsx
152
+
importReactfrom'react'
153
+
154
+
typeProps= { title:string }
155
+
const Component = ({ title, children }:Props) => <divtitle={title}>{children}</div>
156
+
```
157
+
158
+
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.
159
+
160
+
161
+
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.
0 commit comments