{"name":"mobx-react","version":"5.3.2","description":"React bindings for MobX. Create fully reactive components.","main":"index.js","jsnext:main":"index.module.js","module":"index.module.js","react-native":"native.js","typings":"index","repository":{"type":"git","url":"git+https://github.com/mobxjs/mobx-react.git"},"scripts":{"prettier":"prettier --write \"**/*.js\" \"**/*.ts\"","test":"jest && npm run test:ts","test:ts":"tsc -p test/ts","test:travis":"npm run build && jest && npm run test:ts","build":"node build-rollup.js && shx cp src/index.d.ts index.d.ts && shx cp src/index.d.ts native.d.ts && shx cp src/index.d.ts custom.d.ts","watch":"jest --watch"},"author":{"name":"Michel Weststrate"},"license":"MIT","bugs":{"url":"https://github.com/mobxjs/mobx/issues"},"homepage":"https://mobxjs.github.io/mobx","peerDependencies":{"mobx":"^4.0.0 || ^5.0.0","react":"^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0"},"devDependencies":{"@babel/core":"^7.1.0","@babel/plugin-proposal-class-properties":"^7.1.0","@babel/plugin-proposal-decorators":"^7.1.0","@babel/plugin-transform-react-jsx":"^7.0.0","@babel/preset-env":"^7.1.0","@types/create-react-class":"^15.6.0","@types/node":"^10.0.0","@types/prop-types":"^15.5.2","@types/react":"^16.0.13","@types/react-dom":"^16.0.1","babel-core":"^7.0.0-bridge.0","babel-jest":"^23.6.0","create-react-class":"^15.6.2","enzyme":"^3.3.0","enzyme-adapter-react-16":"^1.0.0","husky":"^1.0.0","jest":"^23.6.0","jest-environment-jsdom":"^23.4.0","lint-staged":"^7.0.5","lodash":"^4.17.4","mobx":"^5.0.0","opn-cli":"^3.1.0","prettier":"^1.7.2","prop-types":"^15.6.0","react":"^16.0.0","react-dom":"^16.0.0","react-test-renderer":"^16.0.0","regenerator-runtime":"^0.12.1","request":"^2.83.0","rollup":"^0.66.2","rollup-plugin-alias":"^1.3.0","rollup-plugin-babel":"^4.0.3","rollup-plugin-commonjs":"^9.0.0","rollup-plugin-filesize":"^5.0.0","rollup-plugin-node-resolve":"^3.0.0","rollup-plugin-replace":"^2.1.0","rollup-plugin-uglify":"^6.0.0","shelljs":"^0.8.2","shx":"^0.3.2","typescript":"^2.6.0"},"dependencies":{"hoist-non-react-statics":"^3.0.0","react-lifecycles-compat":"^3.0.2"},"keywords":["mobx","mobservable","react-component","react","reactjs","reactive"],"lint-staged":{"*.{ts,js}":["prettier --write","git add"]},"jest":{},"husky":{"hooks":{"pre-commit":"lint-staged"}},"gitHead":"9589bbf2f2a647cb30877c5db0f87af366a7736d","_id":"mobx-react@5.3.2","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"mweststrate","email":"mweststrate@gmail.com"},"dist":{"integrity":"sha512-4LTK3JSwyfhJ0sNBPOyTyCcEK3wJ0fB4LRUJtOyJL3nZcH/UgsmzTSIbhSU4CeTXOmvZDbyhfi+B14HmL5oLRg==","shasum":"5cd0ae1911385cf55ad02938465d4b4e03dcb0f7","tarball":"http://registry-npm.ywwl.com/mobx-react/download/mobx-react-5.3.2.tgz","fileCount":21,"unpackedSize":559983,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbyILaCRA9TVsSAnZWagAAVqoP/RQ3qu1WwqNgc1fTVgDV\nkK6l6wuM6hsjCXCxjD/tK52IJ3Pkf4ZnnC3o0WY/XjOZESUdCO9kWk46VIlL\noz1VX1jIoUzV/JXMsIdpEp20iMQ5Lr75aO0Qw1ypYbXLoPTI+s/yUHGh1Byb\n4culLhNF4t5atQxEusRDcqNophNTedvT2D7J06PSvSYmM/P1otojkEWkACzC\ngl3KhEhKrS/5+Weu9JdV+mmpKHUydyzOD6PIa9Vve044L3F0ckP8KUR0W6z4\nyDdvwyJ3oSDeXSFT+RY4OqWhwvvZFx2/2lKsMes5rZ0RWTQeKjA34bwloamt\nTgYXTgxFljpFM1LgLT8GtZrwgY2ci5GZl+mWRY636F7tatApRIvydraEtSug\ne3h6JdujXqq5CKlZkIFnhsSipoOZUi98hap/XVEGCZ3AavrrzlIFwjTFhEOs\nxh/BINbZyB7JSOafTlEQS3aNs8Sv32UWNBGRUAcXVikHshcQhUmitQZmjA+f\nmmKM8x4CEM8K3fkTkqIeRlK/PEgK32IkjNwROT41PL8gDySFbvsEiYTB/9K7\njdINQxwusKQ/Vts1/412uW4AZSZ/Nov9I2mE1Ue5lqyRp2Wm/I8SdCB5buJM\nKwDjFU57DFHCfUjOP7ZZhimPuzKt+uKJqn2fCmq/TonA5RQ/sjvsptv1m9U0\nrlvW\r\n=s/NP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGVFWAx8H84bLuWwND0cOrfoWwPukZ+/JwqMIlEPdVc0AiBj6JKlwegtrYFPwAVILOGZK32U4RwHbtsJB6K9QhKcVA=="}],"size":174659,"noattachment":false,"key":"/mobx-react/-/mobx-react-5.3.2.tgz"},"maintainers":[{"email":"mail@andykog.com","name":"andykog"},{"email":"strate@yandex.ru","name":"eshenbrener"},{"email":"mweststrate@gmail.com","name":"mweststrate"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mobx-react_5.3.2_1539867353741_0.1124420981442058"},"_hasShrinkwrap":false,"readme":"# mobx-react\n\n[![CircleCI](https://circleci.com/gh/mobxjs/mobx-react.svg?style=svg)](https://circleci.com/gh/mobxjs/mobx-react)\n[![CDNJS](https://img.shields.io/cdnjs/v/mobx-react.svg)](https://cdnjs.com/libraries/mobx-react)\n[![Minzipped size](https://img.shields.io/bundlephobia/minzip/mobx-react.svg)](https://bundlephobia.com/result?p=mobx-react)\n[![Discuss on Github](https://img.shields.io/badge/discuss%20on-GitHub-orange)](https://github.com/mobxjs/mobx/discussions)\n[![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/mobx-react)\n\nPackage with React component wrapper for combining React with MobX.\nExports the `observer` decorator and other utilities.\nFor documentation, see the [MobX](https://mobx.js.org) project.\nThis package supports both React and React Native.\n\n## Compatibility matrix\n\nOnly the latest version is actively maintained. If you're missing a fix or a feature in older version, consider upgrading or using [patch-package](https://www.npmjs.com/package/patch-package)\n\n| NPM Version | Support MobX version | Supported React versions | Added support for:                                                               |\n| ----------- | -------------------- | ------------------------ | -------------------------------------------------------------------------------- |\n| v9          | 6.\\*                 | >16.8                    | Hooks, React 18.2 in strict mode                                                 |\n| v7          | 6.\\*                 | >16.8 < 18.2             | Hooks                                                                            |\n| v6          | 4.\\* / 5.\\*          | >16.8 <18                | Hooks                                                                            |\n| v5          | 4.\\* / 5.\\*          | >0.13 <18                | No, but it is possible to use `<Observer>` sections inside hook based components |\n\nmobx-react 6 / 7 is a repackage of the smaller [mobx-react-lite](https://github.com/mobxjs/mobx/tree/main/packages/mobx-react-lite) package + following features from the `mobx-react@5` package added:\n\n-   Support for class based components for `observer` and `@observer`\n-   `Provider / inject` to pass stores around (but consider to use `React.createContext` instead)\n-   `PropTypes` to describe observable based property checkers (but consider to use TypeScript instead)\n-   The `disposeOnUnmount` utility / decorator to easily clean up resources such as reactions created in your class based components.\n\n## Installation\n\n`npm install mobx-react --save`\n\nOr CDN: https://unpkg.com/mobx-react (UMD namespace: `mobxReact`)\n\n```javascript\nimport { observer } from \"mobx-react\"\n```\n\nThis package provides the bindings for MobX and React.\nSee the [official documentation](https://mobx.js.org/react-integration.html) for how to get started.\n\nFor greenfield projects you might want to consider to use [mobx-react-lite](https://github.com/mobxjs/mobx/tree/main/packages/mobx-react-lite), if you intend to only use function based components. `React.createContext` can be used to pass stores around.\n\n## API documentation\n\nPlease check [mobx.js.org](https://mobx.js.org/) for the general documentation. The documentation below highlights some specifics.\n\n### `observer(component)`\n\nFunction (and decorator) that converts a React component definition, React component class, or stand-alone render function, into a reactive component. A converted component will track which observables are used by its effective `render` and automatically re-render the component when one of these values changes.\n\n#### Functional Components\n\n`React.memo` is automatically applied to functional components provided to `observer`. `observer` does not accept a functional component already wrapped in `React.memo`, or an `observer`, in order to avoid consequences that might arise as a result of wrapping it twice.\n\n#### Class Components\n\n`shouldComponentUpdate` is not supported. As such, it is recommended that class components extend `React.PureComponent`. The `observer` will automatically patch non-pure class components with an internal implementation of `React.PureComponent` if necessary.\n\nExtending `observer` class components is not supported. Always apply `observer` only on the last class in the inheritance chain.\n\nSee the [MobX](https://mobx.js.org/react-integration.html#react-integration) documentation for more details.\n\n```javascript\nimport { observer } from \"mobx-react\"\n\n// ---- ES6 syntax ----\nconst TodoView = observer(\n    class TodoView extends React.Component {\n        render() {\n            return <div>{this.props.todo.title}</div>\n        }\n    }\n)\n\n// ---- ESNext syntax with decorator syntax enabled ----\n@observer\nclass TodoView extends React.Component {\n    render() {\n        return <div>{this.props.todo.title}</div>\n    }\n}\n\n// ---- or just use function components: ----\nconst TodoView = observer(({ todo }) => <div>{todo.title}</div>)\n```\n\n##### Note on using props and state in derivations\n\n`mobx-react` version 6 and lower would automatically turn `this.state` and `this.props` into observables.\nThis has the benefit that computed properties and reactions were able to observe those.\nHowever, since this pattern is fundamentally incompatible with `StrictMode` in React 18.2 and higher, this behavior has been removed in React 18.\n\nAs a result, we recommend to no longer mark properties as `@computed` in observer components if they depend on `this.state` or `this.props`.\n\n```javascript\n@observer\nclass Doubler extends React.Component<{ counter: number }> {\n    @computed // BROKEN! <-- @computed should be removed in mobx-react > 7\n    get doubleValue() {\n        // Changes to this.props will no longer be detected properly, to fix it,\n        // remove the @computed annotation.\n        return this.props * 2\n    }\n\n    render() {\n        return <div>{this.doubleValue}</div>\n    }\n}\n```\n\nSimilarly, reactions will no longer respond to `this.state` / `this.props`. This can be overcome by creating an observable copy:\n\n```javascript\n@observer\nclass Alerter extends React.Component<{ counter: number }> {\n    @observable observableCounter: number\n    reactionDisposer\n\n    constructor(props) {\n        this.observableCounter = counter\n    }\n\n    componentDidMount() {\n        // set up a reaction, by observing the observable,\n        // rather than the prop which is non-reactive:\n        this.reactionDisposer = autorun(() => {\n            if (this.observableCounter > 10) {\n                alert(\"Reached 10!\")\n            }\n        })\n    }\n\n    componentDidUpdate() {\n        // sync the observable from props\n        this.observableCounter = this.props.counter\n    }\n\n    componentWillUnmount() {\n        this.reactionDisposer()\n    }\n\n    render() {\n        return <div>{this.props.counter}</div>\n    }\n}\n```\n\nMobX-react will try to detect cases where `this.props`, `this.state` or `this.context` are used by any other derivation than the `render` method of the owning component and throw.\nThis is to make sure that neither computed properties, nor reactions, nor other components accidentally rely on those fields to be reactive.\n\nThis includes cases where a render callback is passed to a child, that will read from the props or state of a parent component.\nAs a result, passing a function that might later read a property of a parent in a reactive context will throw as well.\nInstead, when using a callback function that is being passed to an `observer` based child, the capture should be captured locally first:\n\n```javascript\n@observer\nclass ChildWrapper extends React.Component<{ counter: number }> {\n    render() {\n        // Collapsible is an observer component that should respond to this.counter,\n        // if it is expanded\n\n        // BAD:\n        return <Collapsible onRenderContent={() => <h1>{this.props.counter}</h1>} />\n\n        // GOOD: (causes to pass down a fresh callback whenever counter changes,\n        // that doesn't depend on its parents props)\n        const counter = this.props.counter\n        return <Collapsible onRenderContent={() => <h1>{counter}</h1>} />\n    }\n}\n```\n\n### `Observer`\n\n`Observer` is a React component, which applies `observer` to an anonymous region in your component.\nIt takes as children a single, argumentless function which should return exactly one React component.\nThe rendering in the function will be tracked and automatically re-rendered when needed.\nThis can come in handy when needing to pass render function to external components (for example the React Native listview), or if you\ndislike the `observer` decorator / function.\n\n```javascript\nclass App extends React.Component {\n    render() {\n        return (\n            <div>\n                {this.props.person.name}\n                <Observer>{() => <div>{this.props.person.name}</div>}</Observer>\n            </div>\n        )\n    }\n}\n\nconst person = observable({ name: \"John\" })\n\nReactDOM.render(<App person={person} />, document.body)\nperson.name = \"Mike\" // will cause the Observer region to re-render\n```\n\nIn case you are a fan of render props, you can use that instead of children. Be advised, that you cannot use both approaches at once, children have a precedence.\nExample\n\n```javascript\nclass App extends React.Component {\n    render() {\n        return (\n            <div>\n                {this.props.person.name}\n                <Observer render={() => <div>{this.props.person.name}</div>} />\n            </div>\n        )\n    }\n}\n\nconst person = observable({ name: \"John\" })\n\nReactDOM.render(<App person={person} />, document.body)\nperson.name = \"Mike\" // will cause the Observer region to re-render\n```\n\n### `useLocalObservable` hook\n\nLocal observable state can be introduced by using the `useLocalObservable` hook, that runs once to create an observable store. A quick example would be:\n\n```javascript\nimport { useLocalObservable, Observer } from \"mobx-react-lite\"\n\nconst Todo = () => {\n    const todo = useLocalObservable(() => ({\n        title: \"Test\",\n        done: true,\n        toggle() {\n            this.done = !this.done\n        }\n    }))\n\n    return (\n        <Observer>\n            {() => (\n                <h1 onClick={todo.toggle}>\n                    {todo.title} {todo.done ? \"[DONE]\" : \"[TODO]\"}\n                </h1>\n            )}\n        </Observer>\n    )\n}\n```\n\nWhen using `useLocalObservable`, all properties of the returned object will be made observable automatically, getters will be turned into computed properties, and methods will be bound to the store and apply mobx transactions automatically. If new class instances are returned from the initializer, they will be kept as is.\n\nIt is important to realize that the store is created only once! It is not possible to specify dependencies to force re-creation, _nor should you directly be referring to props for the initializer function_, as changes in those won't propagate.\n\nInstead, if your store needs to refer to props (or `useState` based local state), the `useLocalObservable` should be combined with the `useAsObservableSource` hook, see below.\n\nNote that in many cases it is possible to extract the initializer function to a function outside the component definition. Which makes it possible to test the store itself in a more straight-forward manner, and avoids creating the initializer closure on each re-render.\n\n_Note: using `useLocalObservable` is mostly beneficial for really complex local state, or to obtain more uniform code base. Note that using a local store might conflict with future React features like concurrent rendering._\n\n### Server Side Rendering with `enableStaticRendering`\n\nWhen using server side rendering, normal lifecycle hooks of React components are not fired, as the components are rendered only once.\nSince components are never unmounted, `observer` components would in this case leak memory when being rendered server side.\nTo avoid leaking memory, call `enableStaticRendering(true)` when using server side rendering.\n\n```javascript\nimport { enableStaticRendering } from \"mobx-react\"\n\nenableStaticRendering(true)\n```\n\nThis makes sure the component won't try to react to any future data changes.\n\n### Which components should be marked with `observer`?\n\nThe simple rule of thumb is: _all components that render observable data_.\nIf you don't want to mark a component as observer, for example to reduce the dependencies of a generic component package, make sure you only pass it plain data.\n\n### Enabling decorators (optional)\n\nDecorators are currently a stage-2 ESNext feature. How to enable them is documented [here](https://mobx.js.org/enabling-decorators.html#enabling-decorators-).\n\n### Should I still use smart and dumb components?\n\nSee this [thread](https://www.reddit.com/r/reactjs/comments/4vnxg5/free_eggheadio_course_learn_mobx_react_in_30/d61oh0l).\nTL;DR: the conceptual distinction makes a lot of sense when using MobX as well, but use `observer` on all components.\n\n### `PropTypes`\n\nMobX-react provides the following additional `PropTypes` which can be used to validate against MobX structures:\n\n-   `observableArray`\n-   `observableArrayOf(React.PropTypes.number)`\n-   `observableMap`\n-   `observableObject`\n-   `arrayOrObservableArray`\n-   `arrayOrObservableArrayOf(React.PropTypes.number)`\n-   `objectOrObservableObject`\n\nUse `import { PropTypes } from \"mobx-react\"` to import them, then use for example `PropTypes.observableArray`\n\n### `Provider` and `inject`\n\n_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`._\n\n`Provider` is a component that can pass stores (or other stuff) using React's context mechanism to child components.\nThis is useful if you have things that you don't want to pass through multiple layers of components explicitly.\n\n`inject` can be used to pick up those stores. It is a higher order component that takes a list of strings and makes those stores available to the wrapped component.\n\nExample (based on the official [context docs](https://facebook.github.io/react/docs/context.html#passing-info-automatically-through-a-tree)):\n\n```javascript\n@inject(\"color\")\n@observer\nclass Button extends React.Component {\n    render() {\n        return <button style={{ background: this.props.color }}>{this.props.children}</button>\n    }\n}\n\nclass Message extends React.Component {\n    render() {\n        return (\n            <div>\n                {this.props.text} <Button>Delete</Button>\n            </div>\n        )\n    }\n}\n\nclass MessageList extends React.Component {\n    render() {\n        const children = this.props.messages.map(message => <Message text={message.text} />)\n        return (\n            <Provider color=\"red\">\n                <div>{children}</div>\n            </Provider>\n        )\n    }\n}\n```\n\nNotes:\n\n-   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`.\n-   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!\n-   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.\n-   The original component wrapped by `inject` is available as the `wrappedComponent` property of the created higher order component.\n\n#### \"The set of provided stores has changed\" error\n\nValues 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.\nThis 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://reactjs.org/docs/context.html) directly which does not have this restriction.\n\n#### Inject as function\n\nThe above example in ES5 would start like:\n\n```javascript\nvar Button = inject(\"color\")(\n    observer(\n        class Button extends Component {\n            /* ... etc ... */\n        }\n    )\n)\n```\n\nA functional stateless component would look like:\n\n```javascript\nvar Button = inject(\"color\")(\n    observer(({ color }) => {\n        /* ... etc ... */\n    })\n)\n```\n\n#### Customizing inject\n\nInstead of passing a list of store names, it is also possible to create a custom mapper function and pass it to inject.\nThe mapper function receives all stores as argument, the properties with which the components are invoked and the context, and should produce a new set of properties,\nthat are mapped into the original:\n\n`mapperFunction: (allStores, props, context) => additionalProps`\n\nSince version 4.0 the `mapperFunction` itself is tracked as well, so it is possible to do things like:\n\n```javascript\nconst NameDisplayer = ({ name }) => <h1>{name}</h1>\n\nconst UserNameDisplayer = inject(stores => ({\n    name: stores.userStore.name\n}))(NameDisplayer)\n\nconst user = mobx.observable({\n    name: \"Noa\"\n})\n\nconst App = () => (\n    <Provider userStore={user}>\n        <UserNameDisplayer />\n    </Provider>\n)\n\nReactDOM.render(<App />, document.body)\n```\n\n_N.B. note that in this *specific* case neither `NameDisplayer` nor `UserNameDisplayer` needs to be decorated with `observer`, since the observable dereferencing is done in the mapper function_\n\n#### Using `PropTypes` and `defaultProps` and other static properties in combination with `inject`\n\nInject wraps a new component around the component you pass into it.\nThis means that assigning a static property to the resulting component, will be applied to the HoC, and not to the original component.\nSo if you take the following example:\n\n```javascript\nconst UserName = inject(\"userStore\")(({ userStore, bold }) => someRendering())\n\nUserName.propTypes = {\n    bold: PropTypes.boolean.isRequired,\n    userStore: PropTypes.object.isRequired // will always fail\n}\n```\n\nThe above propTypes are incorrect, `bold` needs to be provided by the caller of the `UserName` component and is checked by React.\nHowever, `userStore` does not need to be required! Although it is required for the original stateless function component, it is not\nrequired for the resulting inject component. After all, the whole point of that component is to provide that `userStore` itself.\n\nSo if you want to make assertions on the data that is being injected (either stores or data resulting from a mapper function), the propTypes\nshould be defined on the _wrapped_ component. Which is available through the static property `wrappedComponent` on the inject component:\n\n```javascript\nconst UserName = inject(\"userStore\")(({ userStore, bold }) => someRendering())\n\nUserName.propTypes = {\n    bold: PropTypes.boolean.isRequired // could be defined either here ...\n}\n\nUserName.wrappedComponent.propTypes = {\n    // ... or here\n    userStore: PropTypes.object.isRequired // correct\n}\n```\n\nThe same principle applies to `defaultProps` and other static React properties.\nNote that it is not allowed to redefine `contextTypes` on `inject` components (but is possible to define it on `wrappedComponent`)\n\nFinally, mobx-react will automatically move non React related static properties from wrappedComponent to the inject component so that all static fields are\nactually available to the outside world without needing `.wrappedComponent`.\n\n#### Strongly typing inject\n\n##### With TypeScript\n\n`inject` also accepts a function (`(allStores, nextProps, nextContext) => additionalProps`) that can be used to pick all the desired stores from the available stores like this.\nThe `additionalProps` will be merged into the original `nextProps` before being provided to the next component.\n\n```typescript\nimport { IUserStore } from \"myStore\"\n\n@inject(allStores => ({\n    userStore: allStores.userStore as IUserStore\n}))\nclass MyComponent extends React.Component<{ userStore?: IUserStore; otherProp: number }, {}> {\n    /* etc */\n}\n```\n\nMake sure to mark `userStore` as an optional property. It should not (necessarily) be passed in by parent components at all!\n\nNote: If you have strict null checking enabled, you could muffle the nullable type by using the `!` operator:\n\n```\npublic render() {\n   const {a, b} = this.store!\n   // ...\n}\n```\n\n#### Testing store injection\n\nIt 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.\n\nSo if you have in your app something like:\n\n```javascript\n<Provider profile={profile}>\n    <Person age={\"30\"} />\n</Provider>\n```\n\nIn your test you can easily test the `Person` component by passing the necessary store as prop directly:\n\n```\nconst profile = new Profile()\nconst mountedComponent = mount(\n   <Person age={'30'} profile={profile} />\n)\n```\n\nBear in mind that using shallow rendering won't provide any useful results when testing injected components; only the injector will be rendered.\nTo test with shallow rendering, instantiate the `wrappedComponent` instead: `shallow(<Person.wrappedComponent />)`\n\n### disposeOnUnmount(componentInstance, propertyKey | function | function[])\n\nFunction (and decorator) that makes sure a function (usually a disposer such as the ones returned by `reaction`, `autorun`, etc.) is automatically executed as part of the componentWillUnmount lifecycle event.\n\n```javascript\nimport { disposeOnUnmount } from \"mobx-react\"\n\nclass SomeComponent extends React.Component {\n    // decorator version\n    @disposeOnUnmount\n    someReactionDisposer = reaction(...)\n\n    // decorator version with arrays\n    @disposeOnUnmount\n    someReactionDisposers = [\n        reaction(...),\n        reaction(...)\n    ]\n\n\n    // function version over properties\n    someReactionDisposer = disposeOnUnmount(this, reaction(...))\n\n    // function version inside methods\n    componentDidMount() {\n        // single function\n        disposeOnUnmount(this, reaction(...))\n\n        // or function array\n        disposeOnUnmount(this, [\n            reaction(...),\n            reaction(...)\n        ])\n    }\n}\n```\n\n## DevTools\n\n`mobx-react@6` and higher are no longer compatible with the mobx-react-devtools.\nThat is, the MobX react devtools will no longer show render timings or dependency trees of the component.\nThe reason is that the standard React devtools are also capable of highlighting re-rendering components.\nAnd the dependency tree of a component can now be inspected by the standard devtools as well, as shown in the image below:\n\n![hooks.png](hooks.png)\n\n## FAQ\n\n**Should I use `observer` for each component?**\n\nYou should use `observer` on every component that displays observable data.\nEven the small ones. `observer` allows components to render independently from their parent and in general this means that\nthe more you use `observer`, the better the performance become.\nThe overhead of `observer` itself is negligible.\nSee also [Do child components need `@observer`?](https://github.com/mobxjs/mobx/issues/101)\n\n**I see React warnings about `forceUpdate` / `setState` from React**\n\nThe following warning will appear if you trigger a re-rendering between instantiating and rendering a component:\n\n```\n\nWarning: forceUpdate(...): Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.`\n\n```\n\n-- or --\n\n```\n\nWarning: 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`.\n\n```\n\nUsually this means that (another) component is trying to modify observables used by this components in their `constructor` or `getInitialState` methods.\nThis violates the React Lifecycle, `componentWillMount` should be used instead if state needs to be modified before mounting.\n","publish_time":1539867353887,"_cnpm_publish_time":1539867353887,"dist-tags":{"latest":"10.0.3"}}