File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ Furthermore by providing Interface declarations describing your API contracts yo
25
25
- [ React] ( #react )
26
26
- [ Stateless Component] ( #stateless-component )
27
27
- [ Class Component] ( #class-component )
28
+ - [ Generic Component] ( #generic-component )
28
29
- [ Higher-Order Component] ( #higher-order-component )
29
30
- [ Redux Connected Component] ( #redux-connected-component )
30
31
- [ Redux] ( #redux )
@@ -128,6 +129,67 @@ export default MyComponent;
128
129
129
130
---
130
131
132
+ ## Generic Component
133
+ - generic component boilerplate
134
+ ``` tsx
135
+ type GenericListProps <T > = {
136
+ dataSource: T [],
137
+ itemRenderer: (item : T ) => JSX .Element ,
138
+ };
139
+
140
+ class GenericList <T > extends React .Component <GenericListProps <T >, {}> {
141
+ render() {
142
+ const { dataSource, itemRenderer } = this .props ;
143
+
144
+ return (
145
+ <div >
146
+ { dataSource .map (itemRenderer )}
147
+ </div >
148
+ );
149
+ }
150
+ }
151
+ ```
152
+
153
+ ``` tsx
154
+ interface IUser {
155
+ id: string ,
156
+ name: string ,
157
+ }
158
+
159
+ type UserItemProps = {
160
+ dataSource: IUser ,
161
+ };
162
+
163
+ cosnt UserItem : React .StatelessComponent < UserItemProps > = ({id , name }) => {
164
+ return (
165
+ <div >
166
+ <b >{ name } </b >
167
+ <small >({ id } )</small >
168
+ </div >
169
+ );
170
+ }
171
+ ```
172
+
173
+ ``` tsx
174
+ const UserList = class extends Table <IUser > { };
175
+
176
+ const users = [{
177
+ id: ' uuidv4' ,
178
+ name: ' Dude' ,
179
+ }];
180
+
181
+ ReactDOM .render (
182
+ <UserList
183
+ dataSource = { users }
184
+ itemRenderer = { item => <UserItem dataSource = { item } />}
185
+ >
186
+ </UserList >
187
+ );
188
+
189
+ ```
190
+
191
+ ---
192
+
131
193
## Higher-Order Component
132
194
- wrap and decorate input Component returning a new Component
133
195
- new Component will inherit Props interface through composition from input Component extended with Props of ` HOC `
You can’t perform that action at this time.
0 commit comments