Skip to content

Commit b7be9e1

Browse files
committed
Updating SFC example
1 parent a8b5d3d commit b7be9e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ Or you can use the provided generic type for functional components:
107107
const App: React.SFC<{ message: string }> = ({ message }) => <div>{message}</div>;
108108
```
109109

110-
Quite frankly I prefer the former pattern as it's shorter.
110+
Quite frankly I prefer the former pattern as it's shorter. However, if you need to use `children` property inside the function body, in the former case it has to be added explicitly. `SFC<T>` already includes the correctly typed `children` property which then doesn't have to become part of your type.
111+
112+
```tsx
113+
const Title: React.SFC<{ title: string }> = ({ children, title }) => (
114+
<div title={title}>{children}</div>
115+
);
116+
```
111117

112118
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
113119

0 commit comments

Comments
 (0)