質問編集履歴

1

自身で書いたコードを追加しました

2020/02/27 07:28

投稿

ssbb
ssbb

スコア24

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,61 @@
79
79
  </div>
80
80
 
81
81
  ```
82
+
83
+
84
+
85
+ ###自身で書いたコード
86
+
87
+ ```tsx
88
+
89
+
90
+
91
+ //関数②
92
+
93
+ const getChild = (obj) => {
94
+
95
+
96
+
97
+ if (obj["children"] !== undefined) {
98
+
99
+ const elements = createElement(obj["children"]);
100
+
101
+ // ここで詰まり質問に至りました。。
102
+
103
+ } else {
104
+
105
+ return React.createElement(obj["elmType"], {}, null);
106
+
107
+ }
108
+
109
+ };
110
+
111
+
112
+
113
+ //関数①
114
+
115
+ const createElement = (obj) => {
116
+
117
+ if (obj.length !== undefined) {
118
+
119
+ return obj.map((obj2) => {
120
+
121
+ return getChild(obj2);
122
+
123
+ });
124
+
125
+ } else {
126
+
127
+ return getChild(obj);
128
+
129
+ }
130
+
131
+ };
132
+
133
+
134
+
135
+ const customFormatter = JSON.parse(CustomFormatter); //CustomFormatterがJSONになります
136
+
137
+ const html = createElement(customFormatter);
138
+
139
+ ```