@@ -24,9 +24,9 @@ Furthermore by providing Interface declarations describing your API contracts yo
24
24
25
25
### Table of Contents
26
26
- [ React] ( #react )
27
- - [ Stateless Component] ( #stateless-component )
27
+ - [ Stateless Component - SFC ] ( #stateless-component-sfc )
28
28
- [ Class Component] ( #class-component )
29
- - [ Generic Component] ( #generic-component )
29
+ - [ Generic List Component] ( #generic-list -component )
30
30
- [ Connected Container with OwnProps] ( #connected-container-with-ownprops )
31
31
- [ Connected Container without OwnProps using Type Inference] ( #connected-container-without-ownprops-using-type-inference )
32
32
- [ Higher-Order Component] ( #higher-order-component )
@@ -54,8 +54,9 @@ Furthermore by providing Interface declarations describing your API contracts yo
54
54
55
55
---
56
56
57
- ## Stateless Component
57
+ ## Stateless Component - SFC
58
58
- stateless component boilerplate
59
+ - convenient alias: ` React.SFC<Props> === React.StatelessComponent<Props> `
59
60
``` tsx
60
61
import * as React from ' react' ;
61
62
@@ -64,7 +65,7 @@ type Props = {
64
65
style? : React .CSSProperties ,
65
66
};
66
67
67
- const MyComponent: React .StatelessComponent <Props > = (props ) => {
68
+ const MyComponent: React .SFC <Props > = (props ) => {
68
69
const { children, ... restProps } = props ;
69
70
return (
70
71
<div { ... restProps } >
@@ -131,21 +132,21 @@ export default MyComponent;
131
132
132
133
---
133
134
134
- ## Generic Component
135
+ ## Generic List Component
135
136
- generic component boilerplate
136
137
``` tsx
137
138
type GenericListProps <T > = {
138
- dataSource : T [],
139
+ items : T [],
139
140
itemRenderer: (item : T ) => JSX .Element ,
140
141
};
141
142
142
143
class GenericList <T > extends React .Component <GenericListProps <T >, {}> {
143
144
render() {
144
- const { dataSource , itemRenderer } = this .props ;
145
+ const { items , itemRenderer } = this .props ;
145
146
146
147
return (
147
148
<div >
148
- { dataSource .map (itemRenderer )}
149
+ { items .map (itemRenderer )}
149
150
</div >
150
151
);
151
152
}
@@ -159,10 +160,12 @@ interface IUser {
159
160
}
160
161
161
162
type UserItemProps = {
162
- dataSource : IUser ,
163
+ item : IUser ,
163
164
};
164
165
165
- cosnt UserItem : React .StatelessComponent < UserItemProps > = ({id , name }) => {
166
+ const UserItem: React .SFC <UserItemProps > = ({item }) => {
167
+ const {name, id} = item ;
168
+
166
169
return (
167
170
<div >
168
171
<b >{ name } </b >
@@ -173,7 +176,7 @@ cosnt UserItem: React.StatelessComponent<UserItemProps> = ({id, name}) => {
173
176
```
174
177
175
178
``` tsx
176
- const UserList = class extends Table <IUser > { };
179
+ const UserList = class extends GenericList <IUser > { };
177
180
178
181
const users = [{
179
182
id: ' uuidv4' ,
@@ -182,12 +185,11 @@ const users = [{
182
185
183
186
ReactDOM .render (
184
187
<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
187
190
>
188
191
</UserList >
189
192
);
190
-
191
193
```
192
194
193
195
---
@@ -321,7 +323,7 @@ type Props = {
321
323
type? : typeof Button .prototype .props .type ,
322
324
};
323
325
324
- const ButtonControl: React .StatelessComponent <Props > = (props ) => {
326
+ const ButtonControl: React .SFC <Props > = (props ) => {
325
327
const { children, ... restProps } = props ;
326
328
327
329
return (
@@ -359,9 +361,9 @@ type FormItemProps = {
359
361
360
362
export function withFormItem<WrappedComponentProps extends BaseProps >(
361
363
WrappedComponent :
362
- React .StatelessComponent <WrappedComponentProps > | React .ComponentClass <WrappedComponentProps >,
364
+ React .SFC <WrappedComponentProps > | React .ComponentClass <WrappedComponentProps >,
363
365
) {
364
- const HOC: React .StatelessComponent <HOCProps & WrappedComponentProps > =
366
+ const HOC: React .SFC <HOCProps & WrappedComponentProps > =
365
367
(props ) => {
366
368
const {
367
369
label, labelCol, wrapperCol, required, help, validateStatus, colon,
@@ -890,7 +892,7 @@ Using this solution you'll achieve better encapsulation for internal structure/n
890
892
// 1. in `components/` folder create component file (`select.tsx`) with default export:
891
893
892
894
// components/select.tsx
893
- const Select: React .StatelessComponent <Props > = (props ) => {
895
+ const Select: React .SFC <Props > = (props ) => {
894
896
...
895
897
export default Select ;
896
898
0 commit comments