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
{{ message }}
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+37-1Lines changed: 37 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ There are currently two actively maintained versions of mobx-react:
19
19
| v6 | 16.8.0 and higher | Yes |
20
20
| v5 | 0.13 and higher | No, but it is possible to use `<Observer>` sections inside hook based components |
21
21
22
-
The user guide covers this [in a more detail](https://mobx-react.js.org/libraries).
22
+
The user guide covers this [in a more detail](https://mobx-react.js.org/libraries).
23
23
24
24
The V5 documentation can be found in the [README_v5](README_v5.md).
25
25
@@ -319,6 +319,7 @@ Notes:
319
319
- The original component wrapped by `inject` is available as the `wrappedComponent` property of the created higher order component.
320
320
321
321
#### "The set of provided stores has changed" error
322
+
322
323
Values provided through `Provider` should be final. Make sure that if you put things in `context` that might change over time, that they are `@observable` or provide some other means to listen to changes, like callbacks. However, if your stores will change over time, like an observable value of another store, MobX will throw an error.
323
324
This restriction exists mainly for legacy reasons. If you have a scenario where you need to modify the set of stores, please leave a comment about it in this issue https://github.com/mobxjs/mobx-react/issues/745. Or a preferred way is to [use React Context](https://mobx-react.js.org/recipes-context) directly which does not have this restriction.
324
325
@@ -520,6 +521,36 @@ And the dependency tree of a component can now be inspected by the standard devt
520
521
521
522

522
523
524
+
## Observer batching
525
+
526
+
[Check out the elaborate explanation](https://github.com/mobxjs/mobx-react/pull/787#issuecomment-573599793).
527
+
528
+
In short without observer batching the React doesn't guarantee the order component rendering in some cases. We highly recommend that you configure batching to avoid these random surprises.
529
+
530
+
Import one of these before any React rendering is happening, typically `index.js/ts`. For Jest tests you can utilize [setupFilesAfterEnv](https://jestjs.io/docs/en/configuration#setupfilesafterenv-array).
531
+
532
+
**React DOM:**
533
+
534
+
> import 'mobx-react/batchingForReactDom'
535
+
536
+
**React Native:**
537
+
538
+
> import 'mobx-react/batchingForReactNative'
539
+
540
+
### Opt-out
541
+
542
+
To opt-out from batching in some specific cases, simply import the following to silence the warning.
543
+
544
+
> import 'mobx-react/batchingOptOut'
545
+
546
+
### Custom batched updates
547
+
548
+
Above imports are for a convenience to utilize standard versions of batching. If you for some reason have customized version of batched updates, you can do the following instead.
549
+
550
+
```js
551
+
import { observerBatching } from"mobx-react"
552
+
observerBatching(customBatchedUpdates)
553
+
523
554
## FAQ
524
555
525
556
**Should I use `observer`for each component?**
@@ -535,14 +566,19 @@ See also [Do child components need `@observer`?](https://github.com/mobxjs/mobx/
535
566
The following warning will appear if you trigger a re-rendering between instantiating and rendering a component:
536
567
537
568
```
569
+
538
570
Warning: forceUpdate(...): Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.`
571
+
539
572
```
540
573
541
574
-- or --
542
575
543
576
```
577
+
544
578
Warning:setState(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.
579
+
545
580
```
546
581
547
582
Usually this means that (another) component is trying to modify observables used by this components in their `constructor` or `getInitialState` methods.
548
583
This violates the React Lifecycle, `componentWillMount` should be used instead if state needs to be modified before mounting.
0 commit comments