You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: part-two.md
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ This method removes a child node. Again we used this in our reconciler.
93
93
94
94
**`render`**
95
95
96
-
As we already have appended the child node using `appendChild`, so it's safe to return noop. However, this may vary in your host environment where you might want to render something initially.
96
+
As we have already appended the child node using `appendChild`, `officegen` ensures that the child (text) is added to its main instance, so we can safely return noop in render. However, this may vary in your host environment where after appending the child node using platform specific API, you also might want to render something.
97
97
98
98
Let's create the `Text` component
99
99
@@ -162,6 +162,61 @@ In `appendChild`, we also check whether the `child` is a component or not. If it
162
162
</Document>
163
163
```
164
164
165
+
#### Note
166
+
167
+
* Do not track the children inside an array in your class component API. Instead, directly append them using specific host API, as React provides all the valuable information about the child (which was removed or added)
168
+
169
+
This is correct
170
+
171
+
```js
172
+
173
+
classMyComponent {
174
+
constructor(rootInstance, props) {
175
+
this.props= props
176
+
this.root= rootInstance
177
+
}
178
+
179
+
appendChild(child) {
180
+
some_platform_api.add(child)
181
+
// In browser, you may use something like: document.appendChild(child)
182
+
}
183
+
184
+
render() {
185
+
// do something or return noop if root instance already contains the child node (this vary in different host environment)
186
+
}
187
+
}
188
+
189
+
```
190
+
191
+
This is incorrect
192
+
193
+
```js
194
+
classMyComponent {
195
+
children = []
196
+
197
+
constructor(rootInstance, props) {
198
+
this.props= props
199
+
this.root= rootInstance
200
+
}
201
+
202
+
appendChild(child) {
203
+
this.children.push(child)
204
+
}
205
+
206
+
renderChildren() {
207
+
for(let i =0; i <this.children.length; i++) {
208
+
// do something with this.children[i]
209
+
}
210
+
}
211
+
212
+
render() {
213
+
this.renderChildren()
214
+
}
215
+
}
216
+
```
217
+
218
+
* If you're rendering target does not provide a mutate method like `appendChild` and instead only lets you replace the whole "scene" at once, you might want to use the "persistent" renderer mode instead. Here's an [example host config for persistent renderer](https://github.com/facebook/react/blob/master/packages/react-native-renderer/src/ReactFabricHostConfig.js).
219
+
165
220
## createElement
166
221
167
222
This is similar to the `React.createElement()` for DOM as a target.
0 commit comments