File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 16
16
- [ Section 1: Reusable Components/Type Utilities] ( #section-1-reusable-componentstype-utilities )
17
17
* [ Higher Order Components] ( #higher-order-components-hocs )
18
18
* [ Render Props] ( #render-props )
19
+ * [ ` as ` props (passing a component to be rendered)] ( #as-props-passing-a-component-to-be-rendered )
19
20
* [ Types for Conditional Rendering] ( #types-for-conditional-rendering )
20
21
* [ Omit attribute from a type] ( #omit-attribute-from-a-type )
21
22
* [ Type Zoo] ( #type-zoo )
@@ -159,6 +160,19 @@ export interface Props {
159
160
160
161
[ Something to add? File an issue] ( https://github.com/sw-yx/react-typescript-cheatsheet/issues/new ) .
161
162
163
+ ## ` as ` props (passing a component to be rendered)
164
+
165
+ ` ReactType ` is pretty useful to cover most types that can be passed to createElement e.g.
166
+
167
+ ``` tsx
168
+ function PassThrough(props : { as: ReactType <any > }) {
169
+ const { as : Component } = props ;
170
+
171
+ return <Component />
172
+ }
173
+ ```
174
+
175
+ [ Thanks @eps1lon ] ( https://github.com/sw-yx/react-typescript-cheatsheet/pull/69 ) for this
162
176
163
177
## Types for Conditional Rendering
164
178
You can’t perform that action at this time.
0 commit comments