File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
10
10
For a steady stream of TILs from a variety of rocketeers, checkout
11
11
[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
12
12
13
- _ 672 TILs and counting..._
13
+ _ 673 TILs and counting..._
14
14
15
15
---
16
16
@@ -465,6 +465,7 @@ _672 TILs and counting..._
465
465
- [ Destructure Variables As Props To A Component] ( react/destructure-variables-as-props-to-a-component.md )
466
466
- [ Dispatch Anywhere With Redux] ( react/dispatch-anywhere-with-redux.md )
467
467
- [ Dynamically Add Props To A Child Component] ( react/dynamically-add-props-to-a-child-component.md )
468
+ - [ Dynamically Create HTML Elements] ( react/dynamically-create-html-elements.md )
468
469
- [ Enforce Specific Values With PropTypes] ( react/enforce-specific-values-with-proptypes.md )
469
470
- [ Force A Component To Only Have One Child] ( react/force-a-component-to-only-have-one-child.md )
470
471
- [ Inactive And Active Component Styles With Radium] ( react/inactive-and-active-component-styles-with-radium.md )
Original file line number Diff line number Diff line change
1
+ # Dynamically Create HTML Elements
2
+
3
+ An HTML element can be created with a string that matches a recognized
4
+ entity.
5
+
6
+ ``` javascript
7
+ const Paragraph = ' p' ;
8
+ return < Paragraph> Some paragraph content< / Paragraph>
9
+ ```
10
+
11
+ This means we can dynamically create HTML elements such as headers:
12
+
13
+ ``` javascript
14
+ const H = ({ level, ... props }) => {
15
+ const Heading = ` h${ Math .min (level, 6 )} ` ;
16
+ return < Heading {... props} / > ;
17
+ };
18
+
19
+ return (
20
+ < React .Fragment >
21
+ < H level= {1 }> Header 1 < / H >
22
+ < H level= {2 }> Header 2 < / H >
23
+ < H level= {5 }> Header 5 < / H >
24
+ < / React .Fragment >
25
+ );
26
+ ```
27
+
28
+ With some
29
+ [ inspiration] ( https://medium.com/@Heydon/managing-heading-levels-in-design-systems-18be9a746fa3 ) ,
30
+ I've created a [ live example here] ( https://codesandbox.io/s/3v202wmmy1 ) .
You can’t perform that action at this time.
0 commit comments