Skip to content

Commit 7dcd8be

Browse files
committed
Update readme with suggested changes
1 parent 9cc99cd commit 7dcd8be

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ To save a new collection key we can either do:
157157
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`, report1);
158158
```
159159

160-
or we can set many at once with `mergeCollection()`:
160+
or we can set many at once with `mergeCollection()` (see below for guidance on best practices):
161161

162162
```js
163163
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, {
@@ -177,7 +177,7 @@ withOnyx({
177177
})(MyComponent);
178178
```
179179

180-
This will return the initial collection as an object of collection member key/values. Changes to the individual member keys will modify the entire object and new props will be passed with each individual key update.
180+
This will add a prop to the component called `allReports` which is an object of collection member key/values. Changes to the individual member keys will modify the entire object and new props will be passed with each individual key update. The prop doesn't update on the initial rendering of the component until the entire collection has been read out of Onyx.
181181

182182
```js
183183
Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT}, callback: (memberValue, memberKey) => {...}});
@@ -203,12 +203,12 @@ Remember, `mergeCollection()` will notify a subscriber only *once* with the tota
203203

204204
```js
205205
// Bad
206-
_.each(reports, report => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report)); // -> Connected component will update on each iteration
206+
_.each(reports, report => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report)); // -> A component using withOnyx() will have it's state updated with each iteration
207207

208208
// Good
209209
const values = {};
210210
_.each(reports, report => values[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = report);
211-
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, values); // -> Connected component will update just once
211+
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, values); // -> A component using withOnyx() will only have it's state updated once
212212
```
213213

214214
## Clean up

0 commit comments

Comments
 (0)