Skip to content

Commit 65534dc

Browse files
authored
updated docs
1 parent cda1397 commit 65534dc

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

part-two.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This method removes a child node. Again we used this in our reconciler.
9393

9494
**`render`**
9595

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.
9797

9898
Let's create the `Text` component
9999

@@ -162,6 +162,61 @@ In `appendChild`, we also check whether the `child` is a component or not. If it
162162
</Document>
163163
```
164164

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+
class MyComponent {
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+
class MyComponent {
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+
165220
## createElement
166221

167222
This is similar to the `React.createElement()` for DOM as a target.

0 commit comments

Comments
 (0)