Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add detail/summary wrapper
  • Loading branch information
tsiq-swyx authored Jun 6, 2018
commit d15c3dcfecc9966453f8310268da3992c3597682
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ Or you can use the provided generic type for functional components:
const App: React.SFC<{ message: string }> = ({ message }) => <div>{message}</div>;
```

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.
<details>

<summary><b>Discussion</b></summary>

The former pattern is shorter, so why would people use `React.SFC` at all? 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.

```tsx
const Title: React.SFC<{ title: string }> = ({ children, title }) => (
Expand All @@ -117,6 +121,8 @@ const Title: React.SFC<{ title: string }> = ({ children, title }) => (

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

</details>

## Stateful Class-based Components

Within Typescript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you actually want to provide it with prop and (optionally) state types:
Expand Down