Skip to content

Commit bc60082

Browse files
authored
Update README.md
1 parent e1fdd7a commit bc60082

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Furthermore by providing Interface declarations describing your API contracts yo
2424

2525
### Table of Contents
2626
- [React](#react)
27-
- [Stateless Component](#stateless-component)
27+
- [Stateless Component - SFC](#stateless-component-sfc)
2828
- [Class Component](#class-component)
29-
- [Generic Component](#generic-component)
29+
- [Generic List Component](#generic-list-component)
3030
- [Connected Container with OwnProps](#connected-container-with-ownprops)
3131
- [Connected Container without OwnProps using Type Inference](#connected-container-without-ownprops-using-type-inference)
3232
- [Higher-Order Component](#higher-order-component)
@@ -54,8 +54,9 @@ Furthermore by providing Interface declarations describing your API contracts yo
5454

5555
---
5656

57-
## Stateless Component
57+
## Stateless Component - SFC
5858
- stateless component boilerplate
59+
- convenient alias: `React.SFC<Props> === React.StatelessComponent<Props>`
5960
```tsx
6061
import * as React from 'react';
6162

@@ -64,7 +65,7 @@ type Props = {
6465
style?: React.CSSProperties,
6566
};
6667

67-
const MyComponent: React.StatelessComponent<Props> = (props) => {
68+
const MyComponent: React.SFC<Props> = (props) => {
6869
const { children, ...restProps } = props;
6970
return (
7071
<div {...restProps} >
@@ -131,21 +132,21 @@ export default MyComponent;
131132

132133
---
133134

134-
## Generic Component
135+
## Generic List Component
135136
- generic component boilerplate
136137
```tsx
137138
type GenericListProps<T> = {
138-
dataSource: T[],
139+
items: T[],
139140
itemRenderer: (item: T) => JSX.Element,
140141
};
141142

142143
class GenericList<T> extends React.Component<GenericListProps<T>, {}> {
143144
render() {
144-
const { dataSource, itemRenderer } = this.props;
145+
const { items, itemRenderer } = this.props;
145146

146147
return (
147148
<div>
148-
{dataSource.map(itemRenderer)}
149+
{items.map(itemRenderer)}
149150
</div>
150151
);
151152
}
@@ -159,10 +160,12 @@ interface IUser {
159160
}
160161

161162
type UserItemProps = {
162-
dataSource: IUser,
163+
item: IUser,
163164
};
164165

165-
cosnt UserItem: React.StatelessComponent<UserItemProps> = ({id, name}) => {
166+
const UserItem: React.SFC<UserItemProps> = ({item}) => {
167+
const {name, id} = item;
168+
166169
return (
167170
<div>
168171
<b>{name}</b>
@@ -173,7 +176,7 @@ cosnt UserItem: React.StatelessComponent<UserItemProps> = ({id, name}) => {
173176
```
174177

175178
```tsx
176-
const UserList = class extends Table<IUser> { };
179+
const UserList = class extends GenericList<IUser> { };
177180

178181
const users = [{
179182
id: 'uuidv4',
@@ -182,12 +185,11 @@ const users = [{
182185

183186
ReactDOM.render(
184187
<UserList
185-
dataSource={users}
186-
itemRenderer={(item) => <UserItem key={item.id} dataSource={item} />} // <- notice that "item" has inferred "IUser" type
188+
items={users}
189+
itemRenderer={(item) => <UserItem key={item.id} item={item} />} // <- notice that "items" and "itemRenderer" has inferred "IUser" type
187190
>
188191
</UserList>
189192
);
190-
191193
```
192194

193195
---
@@ -321,7 +323,7 @@ type Props = {
321323
type?: typeof Button.prototype.props.type,
322324
};
323325

324-
const ButtonControl: React.StatelessComponent<Props> = (props) => {
326+
const ButtonControl: React.SFC<Props> = (props) => {
325327
const { children, ...restProps } = props;
326328

327329
return (
@@ -359,9 +361,9 @@ type FormItemProps = {
359361

360362
export function withFormItem<WrappedComponentProps extends BaseProps>(
361363
WrappedComponent:
362-
React.StatelessComponent<WrappedComponentProps> | React.ComponentClass<WrappedComponentProps>,
364+
React.SFC<WrappedComponentProps> | React.ComponentClass<WrappedComponentProps>,
363365
) {
364-
const HOC: React.StatelessComponent<HOCProps & WrappedComponentProps> =
366+
const HOC: React.SFC<HOCProps & WrappedComponentProps> =
365367
(props) => {
366368
const {
367369
label, labelCol, wrapperCol, required, help, validateStatus, colon,
@@ -890,7 +892,7 @@ Using this solution you'll achieve better encapsulation for internal structure/n
890892
// 1. in `components/` folder create component file (`select.tsx`) with default export:
891893

892894
// components/select.tsx
893-
const Select: React.StatelessComponent<Props> = (props) => {
895+
const Select: React.SFC<Props> = (props) => {
894896
...
895897
export default Select;
896898

0 commit comments

Comments
 (0)