mobx-react 6.1.1 → 6.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -7
- package/README.md +17 -3
- package/dist/mobx-react.d.ts +7 -1
- package/dist/mobx-react.js +717 -1
- package/dist/mobx-react.js.map +1 -1
- package/dist/mobx-react.module.js +704 -1
- package/dist/mobx-react.module.js.map +1 -1
- package/dist/mobx-react.rn.module.js +704 -1
- package/dist/mobx-react.umd.js +1 -1
- package/dist/mobx-react.umd.js.map +1 -1
- package/package.json +31 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# MobX-React Changelog
|
|
2
2
|
|
|
3
|
+
### 6.1.5
|
|
4
|
+
|
|
5
|
+
- Added check if `process.env` is available, fixes [#801](https://github.com/mobxjs/mobx-react/issues/801) through [#812](https://github.com/mobxjs/mobx-react/pull/812) by [@ynejati](https://github.com/ynejati)
|
|
6
|
+
- Added warning if component's `render` method is accidentally overwritten. [#799](https://github.com/mobxjs/mobx-react/pull/799) by [@Venryx](https://github.com/Venryx). Helps prevent memory leaks as in: [#797](https://github.com/mobxjs/mobx-react/issues/797)
|
|
7
|
+
|
|
8
|
+
### 6.1.4
|
|
9
|
+
|
|
10
|
+
- Update dependency mobx-react-lite@1.4.2 which includes fix for [RN Fast Refresh](https://github.com/mobxjs/mobx-react-lite/issues/226)
|
|
11
|
+
|
|
12
|
+
### 6.1.2 / 6.1.3
|
|
13
|
+
|
|
14
|
+
- Add reexport of `useObserver` from `mobx-react-lite` [#734](https://github.com/mobxjs/mobx-react/issues/734)
|
|
15
|
+
- Add the ability to pass multiple children to Provider
|
|
16
|
+
- Fixed [#717](https://github.com/mobxjs/mobx-react/issues/717). Now `inject` works correctly with components that use `React.forwardRef`
|
|
17
|
+
- Observer checks for use of React.memo [#720](https://github.com/mobxjs/mobx-react/issues/720)
|
|
18
|
+
- Get rid of the redundant Injector wrapper [#716](https://github.com/mobxjs/mobx-react/pull/716)
|
|
19
|
+
|
|
3
20
|
### 6.1.1
|
|
4
21
|
|
|
5
22
|
- Fixed issue where combining `@disposeOnUnmount` with `disposeOnUnmount` didn't clean up everything. Fixes [#666](https://github.com/mobxjs/mobx-react/issues/666) trough [#671](https://github.com/mobxjs/mobx-react/pull/671) by [@JabX](https://github.com/JabX)
|
|
@@ -52,7 +69,7 @@
|
|
|
52
69
|
**Improvements**
|
|
53
70
|
|
|
54
71
|
- Hook based components are now supported by mobx-react (in fact, the package is now implemented using hooks)
|
|
55
|
-
- Using `PureComponent` is now _recommended_.
|
|
72
|
+
- Using `PureComponent` is now _recommended_ for class-based components or `React.memo` for functional ones.
|
|
56
73
|
- For `observer` based components, there will now be an additional `Observer` component in the tree.
|
|
57
74
|
- Two new hooks have been exposed, in case you want to manage local state in observable: `useLocalStore` and `useAsObservableSource`.
|
|
58
75
|
- `MobXProviderContext` is now exposed from the package, in case you want to consume the context used by `Provider` with a `useContext` hook.
|
|
@@ -136,12 +153,12 @@ _5.3.0 was retracted as files were not generated correctly during publish_
|
|
|
136
153
|
|
|
137
154
|
### 5.1.0
|
|
138
155
|
|
|
139
|
-
- Added support for React 16.3, including support for the `getDerivedStateFromProps` life-cycle hook. MobX will no longer use `componentWillMount` hook internally, so that it can be used in `StrictMode` react as well. Fixes [#447](https://github.com/
|
|
140
|
-
- Static properties of a function component are now automatically hoisted when the component is wrapped by `observer`. Implements [#427](https://github.com/
|
|
141
|
-
- Misspelled export `componentByNodeRegistery` is now properly export as `componentByNodeRegistry` as well, please update consumers, the mispelled version will be dropped in the next major. Fixes [#421](https://github.com/
|
|
142
|
-
- Deprecated the support for the `inject` property on `Observer`, it is fundamentally broken and should not be used. Use `inject` on the enclosing component instead and grab the necessary stores from the closure. Fixes [#423](https://github.com/
|
|
143
|
-
- Added warning about using `observer` on a React.PureComponent, this will become an exception in the next major. Fixes [#309](https://github.com/
|
|
144
|
-
- Mobx-react will now print a warning when combining `observer` with a custom `shouldComponentUpdate` implementation. Fixes [#417](https://github.com/
|
|
156
|
+
- Added support for React 16.3, including support for the `getDerivedStateFromProps` life-cycle hook. MobX will no longer use `componentWillMount` hook internally, so that it can be used in `StrictMode` react as well. Fixes [#447](https://github.com/mobxjs/mobx-react/issues/447)
|
|
157
|
+
- Static properties of a function component are now automatically hoisted when the component is wrapped by `observer`. Implements [#427](https://github.com/mobxjs/mobx-react/pull/427)
|
|
158
|
+
- Misspelled export `componentByNodeRegistery` is now properly export as `componentByNodeRegistry` as well, please update consumers, the mispelled version will be dropped in the next major. Fixes [#421](https://github.com/mobxjs/mobx-react/issues/421)
|
|
159
|
+
- Deprecated the support for the `inject` property on `Observer`, it is fundamentally broken and should not be used. Use `inject` on the enclosing component instead and grab the necessary stores from the closure. Fixes [#423](https://github.com/mobxjs/mobx-react/issues/423)
|
|
160
|
+
- Added warning about using `observer` on a React.PureComponent, this will become an exception in the next major. Fixes [#309](https://github.com/mobxjs/mobx-react/issues/309)
|
|
161
|
+
- Mobx-react will now print a warning when combining `observer` with a custom `shouldComponentUpdate` implementation. Fixes [#417](https://github.com/mobxjs/mobx-react/issues/417)
|
|
145
162
|
|
|
146
163
|
### 5.0.0
|
|
147
164
|
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
Package with React component wrapper for combining React with MobX.
|
|
8
8
|
Exports the `observer` decorator and other utilities.
|
|
9
9
|
For documentation, see the [MobX](https://mobxjs.github.io/mobx) project.
|
|
10
|
+
There is also work-in-progress [user guide](https://mobx-react.js.org) for additional information.
|
|
10
11
|
This package supports both React and React Native.
|
|
11
12
|
|
|
12
13
|
## Choosing your version
|
|
@@ -18,6 +19,8 @@ There are currently two actively maintained versions of mobx-react:
|
|
|
18
19
|
| v6 | 16.8.0 and higher | Yes |
|
|
19
20
|
| v5 | 0.13 and higher | No, but it is possible to use `<Observer>` sections inside hook based components |
|
|
20
21
|
|
|
22
|
+
The user guide covers this [in a more detail](https://mobx-react.js.org/libraries).
|
|
23
|
+
|
|
21
24
|
The V5 documentation can be found in the [README_v5](README_v5.md).
|
|
22
25
|
|
|
23
26
|
Both mobx-react 5 and 6 are compatible with mobx 4 and 5
|
|
@@ -103,7 +106,7 @@ class App extends React.Component {
|
|
|
103
106
|
|
|
104
107
|
const person = observable({ name: "John" })
|
|
105
108
|
|
|
106
|
-
|
|
109
|
+
ReactDOM.render(<App person={person} />, document.body)
|
|
107
110
|
person.name = "Mike" // will cause the Observer region to re-render
|
|
108
111
|
```
|
|
109
112
|
|
|
@@ -124,12 +127,14 @@ class App extends React.Component {
|
|
|
124
127
|
|
|
125
128
|
const person = observable({ name: "John" })
|
|
126
129
|
|
|
127
|
-
|
|
130
|
+
ReactDOM.render(<App person={person} />, document.body)
|
|
128
131
|
person.name = "Mike" // will cause the Observer region to re-render
|
|
129
132
|
```
|
|
130
133
|
|
|
131
134
|
### `useLocalStore` hook
|
|
132
135
|
|
|
136
|
+
[User guide](https://mobx-react.js.org/state-local)
|
|
137
|
+
|
|
133
138
|
Local observable state can be introduced by using the `useLocalStore` hook, that runs once to create an observable store. A quick example would be:
|
|
134
139
|
|
|
135
140
|
```javascript
|
|
@@ -164,6 +169,8 @@ _Note: using `useLocalStore` is mostly beneficial for really complex local state
|
|
|
164
169
|
|
|
165
170
|
### `useAsObservableSource` hook
|
|
166
171
|
|
|
172
|
+
[User guide](https://mobx-react.js.org/state-outsourcing)
|
|
173
|
+
|
|
167
174
|
The `useAsObservableSource` hook can be used to turn any set of values into an observable object that has a stable reference (the same object is returned every time from the hook).
|
|
168
175
|
The goal of this hook is to trap React primitives such as props or state (which are not observable themselves) into a local, observable object
|
|
169
176
|
so that the `store` or any reactions created by the component can safely refer to it, and get notified if any of the values change.
|
|
@@ -255,6 +262,8 @@ Use `import { PropTypes } from "mobx-react"` to import them, then use for exampl
|
|
|
255
262
|
|
|
256
263
|
### `Provider` and `inject`
|
|
257
264
|
|
|
265
|
+
See also [the migration guide to React Hooks](https://mobx-react.js.org/recipes-migration).
|
|
266
|
+
|
|
258
267
|
_Note: usually there is no need anymore to use `Provider` / `inject` in new code bases; most of its features are now covered by `React.createContext`._
|
|
259
268
|
|
|
260
269
|
`Provider` is a component that can pass stores (or other stuff) using React's context mechanism to child components.
|
|
@@ -299,10 +308,13 @@ Notes:
|
|
|
299
308
|
|
|
300
309
|
- It is possible to read the stores provided by `Provider` using `React.useContext`, by using the `MobXProviderContext` context that can be imported from `mobx-react`.
|
|
301
310
|
- If a component asks for a store and receives a store via a property with the same name, the property takes precedence. Use this to your advantage when testing!
|
|
302
|
-
- Values provided through `Provider` should be final, to avoid issues like mentioned in [React #2517](https://github.com/facebook/react/issues/2517) and [React #3973](https://github.com/facebook/react/pull/3973), where optimizations might stop the propagation of new context. Instead, 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 warn you. To suppress that warning explicitly, you can use `suppressChangedStoreWarning={true}` as a prop at your own risk.
|
|
303
311
|
- When using both `@inject` and `@observer`, make sure to apply them in the correct order: `observer` should be the inner decorator, `inject` the outer. There might be additional decorators in between.
|
|
304
312
|
- The original component wrapped by `inject` is available as the `wrappedComponent` property of the created higher order component.
|
|
305
313
|
|
|
314
|
+
#### "The set of provided stores has changed" error
|
|
315
|
+
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.
|
|
316
|
+
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.
|
|
317
|
+
|
|
306
318
|
#### Inject as function
|
|
307
319
|
|
|
308
320
|
The above example in ES5 would start like:
|
|
@@ -429,6 +441,8 @@ public render() {
|
|
|
429
441
|
}
|
|
430
442
|
```
|
|
431
443
|
|
|
444
|
+
By [migrating to React Hooks](https://mobx-react.js.org/recipes-migration) you can avoid problems with TypeScript.
|
|
445
|
+
|
|
432
446
|
#### Testing store injection
|
|
433
447
|
|
|
434
448
|
It is allowed to pass any declared store in directly as a property as well. This makes it easy to set up individual component tests without a provider.
|
package/dist/mobx-react.d.ts
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as React from "react"
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
useObserver,
|
|
8
|
+
useAsObservableSource,
|
|
9
|
+
useLocalStore,
|
|
10
|
+
IObserverOptions,
|
|
11
|
+
Observer
|
|
12
|
+
} from "mobx-react-lite"
|
|
7
13
|
|
|
8
14
|
export type IReactComponent<P = any> =
|
|
9
15
|
| React.StatelessComponent<P>
|