{"name":"mobx-react-lite","version":"2.0.0-test.0","description":"Lightweight React bindings for MobX based on React 16.8 and Hooks","main":"dist/index.js","jsnext:main":"dist/mobxreactlite.es.production.js","module":"dist/mobxreactlite.es.production.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/mobxjs/mobx-react-lite.git"},"scripts":{"prettier":"prettier --write \"**/*.js\" \"**/*.ts\"","lint":"tslint --project .","validate":"tsc --noEmit","test":"jest --watch","test:travis":"yarn validate && yarn lint && yarn coverage","coverage":"jest --coverage","prebuild":"rimraf dist","build":"tsdx build --name mobxReactLite","prepublishOnly":"yarn build"},"author":{"name":"Daniel K."},"license":"MIT","bugs":{"url":"https://github.com/mobxjs/mobx-react-lite/issues"},"homepage":"https://mobxjs.github.io/mobx","peerDependencies":{"mobx":"^4.0.0 || ^5.0.0","react":"^16.8.0"},"devDependencies":{"@types/jest":"24.0.13","@types/node":"12.0.2","@types/react":"16.8.18","@types/react-dom":"16.8.4","coveralls":"3.0.3","husky":"2.3.0","jest":"24.8.0","jest-dom":"3.4.0","jest-environment-jsdom":"24.8.0","jest-mock-console":"1.0.0","lint-staged":"8.1.7","lodash":"4.17.11","mobx":"5.9.4","prettier":"1.17.1","react":"16.8.6","react-dom":"16.8.6","react-hooks-testing-library":"0.5.0","react-test-renderer":"16.8.6","react-testing-library":"7.0.1","rimraf":"2.6.3","ts-jest":"24.0.2","tsdx":"^0.5.12","tslint":"5.16.0","tslint-config-prettier":"1.18.0","typescript":"3.4.5"},"keywords":["mobx","mobservable","react-component","react","reactjs","reactive","hooks","observer","useObserver","useComputer"],"lint-staged":{"*.{ts,js}":["prettier --write","git add"]},"husky":{"hooks":{"pre-commit":"lint-staged"}},"dependencies":{},"readme":"# mobx-react-lite <!-- omit in toc -->\n\n[![Build Status](https://travis-ci.org/mobxjs/mobx-react-lite.svg?branch=master)](https://travis-ci.org/mobxjs/mobx-react-lite)[![Coverage Status](https://coveralls.io/repos/github/mobxjs/mobx-react-lite/badge.svg)](https://coveralls.io/github/mobxjs/mobx-react-lite)\n\n[![Join the chat at https://gitter.im/mobxjs/mobx](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mobxjs/mobx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nThis is a next iteration of [mobx-react](https://github.com/mobxjs/mobx-react) coming from introducing React hooks which simplifies a lot of internal workings of this package.\n\n**You need React version 16.8.0 and above**\n\nClass based components **are not supported** except using `<Observer>` directly in class `render` method. If you want to transition existing projects from classes to hooks (as most of us do), you can use this package alongside the [mobx-react](https://github.com/mobxjs/mobx-react) just fine. The only conflict point is about the `observer` HOC. Subscribe [to this issue](https://github.com/mobxjs/mobx-react/issues/640) for a proper migration guide.\n\n[![NPM](https://nodei.co/npm/mobx-react-lite.png)](https://www.npmjs.com/package/mobx-react-lite)\n\nProject is written in TypeScript and provides type safety out of the box. No Flow Type support is planned at this moment, but feel free to contribute.\n\n## User Guide 👉 https://mobx-react.js.org\n\nThe site contains various examples and recipes for using MobX in React world. Feel free to contribute. The API reference of this package follows 👇.\n\n## API reference ⚒\n\n> **`<Observer>{renderFn}</Observer>`** _([user guide](https://mobx-react.netlify.com/observer-component))_\n\n> **`observer<P>(baseComponent: FunctionComponent<P>, options?: IObserverOptions): FunctionComponent<P>`** _([user guide](https://mobx-react.netlify.com/observer-hoc))_\n\n```ts\ninterface IObserverOptions {\n    // Pass true to use React.forwardRef over the inner component. It's false by the default.\n    forwardRef?: boolean\n}\n```\n\n> **`useObserver<T>(fn: () => T, baseComponentName = \"observed\", options?: IUseObserverOptions): T`** _([user guide](https://mobx-react.netlify.com/observer-hook))_\n\n```ts\ninterface IUseObserverOptions {\n    // optional custom hook that should make a component re-render (or not) upon changes\n    useForceUpdate: () => () => void\n}\n```\n\n**`useLocalStore<T, S>(initializer: () => T, source?: S): T`** _([user guide](https://mobx-react.netlify.com/state-local))_\n\n**`useAsObservableSource<T>(source: T): T`** _([user guide](https://mobx-react.netlify.com/state-outsourcing))_\n\n## React Strict mode ☄\n\nFeel free to try out `mobx-react-lite@next` which is based on latest 1.x, but contains experimental support for handling Concurrent mode in React properly.\n\n## Deprecation notice ⚠\n\nFollowing utilities are still available in the package, but they are deprecated and will be removed in the next major version (2.x). As such, they are not mentioned in the user guide and it's not recommend to continue using these.\n\n---\n\n### `useObservable<T>(initialValue: T): T`\n\n> **Use the `useLocalStore` instead** ([user guide](https://mobx-react.netlify.com/state-local))\n\nReact hook that allows creating observable object within a component body and keeps track of it over renders. Gets all the benefits from [observable objects](https://mobx.js.org/refguide/object.html) including computed properties and methods. You can also use arrays, Map and Set.\n\nWarning: With current implementation you also need to wrap your component to `observer`. It's also possible to have `useObserver` only in case you are not expecting rerender of the whole component.\n\n```tsx\nimport { observer, useObservable, useObserver } from \"mobx-react-lite\"\n\nconst TodoList = () => {\n    const todos = useObservable(new Map<string, boolean>())\n    const todoRef = React.useRef()\n    const addTodo = React.useCallback(() => {\n        todos.set(todoRef.current.value, false)\n        todoRef.current.value = \"\"\n    }, [])\n    const toggleTodo = React.useCallback((todo: string) => {\n        todos.set(todo, !todos.get(todo))\n    }, [])\n\n    return useObserver(() => (\n        <div>\n            {Array.from(todos).map(([todo, done]) => (\n                <div onClick={() => toggleTodo(todo)} key={todo}>\n                    {todo}\n                    {done ? \" ✔\" : \" ⏲\"}\n                </div>\n            ))}\n            <input ref={todoRef} />\n            <button onClick={addTodo}>Add todo</button>\n        </div>\n    ))\n}\n```\n\n#### Lazy initialization\n\nLazy initialization (similar to `React.useState`) is not available. In most cases your observable state should be a plain object which is cheap to create. With `useObserver` the component won't even rerender and state won't be recreated. In case you really want a more complex state or you need to use `observer`, it's very simple to use MobX directly.\n\n```tsx\nimport { observer } from \"mobx-react-lite\"\nimport { observable } from \"mobx\"\nimport { useState } from \"react\"\n\nconst WithComplexState = observer(() => {\n    const [complexState] = useState(() => observable(new HeavyState()))\n    if (complexState.loading) {\n        return <Loading />\n    }\n    return <div>{complexState.heavyName}</div>\n})\n```\n\n[![Edit TodoList](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jzj48v2xry?module=%2Fsrc%2FTodoList.tsx)\n\nNote that if you want to track a single scalar value (string, number, boolean), you would need [a boxed value](https://mobx.js.org/refguide/boxed.html) which is not recognized by `useObservable`. However, we recommend to just `useState` instead which gives you almost same result (with slightly different API).\n\n### `useComputed(func: () => T, inputs: ReadonlyArray<any> = []): T`\n\n> **Use the `useLocalStore` instead** ([user guide](https://mobx-react.netlify.com/state-local))\n\nAnother React hook that simplifies computational logic. It's just a tiny wrapper around [MobX computed](https://mobx.js.org/refguide/computed-decorator.html#-computed-expression-as-function) function that runs computation whenever observable values change. In conjuction with `observer` the component will rerender based on such a change.\n\n```tsx\nconst Calculator = observer(({ hasExploded }: { hasExploded: boolean }) => {\n    const inputRef = React.useRef()\n    const inputs = useObservable([1, 3, 5])\n    const result = useComputed(\n        () => (hasExploded ? \"💣\" : inputs.reduce(multiply, 1) * Number(!hasExploded)),\n        [hasExploded]\n    )\n\n    return (\n        <div>\n            <input ref={inputRef} />\n            <button onClick={() => inputs.push(parseInt(inputRef.current.value) | 1)}>\n                Multiply\n            </button>\n            <div>\n                {inputs.join(\" * \")} = {result}\n            </div>\n        </div>\n    )\n})\n```\n\nNotice that since the computation depends on non-observable value, it has to be passed as a second argument to `useComputed`. There is [React `useMemo`](https://reactjs.org/docs/hooks-reference.html#usememo) behind the scenes and all rules applies here as well except you don't need to specify dependency on observable values.\n\n[![Edit Calculator](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jzj48v2xry?module=%2Fsrc%2FCalculator.tsx)\n\n### `useDisposable<D extends TDisposable>(disposerGenerator: () => D, inputs: ReadonlyArray<any> = []): D`\n\n> **Use the `React.useEffect` instead** ([user guide](https://mobx-react.netlify.com/recipes-effects))\n\nThe disposable is any kind of function that returns another function to be called on a component unmount to clean up used resources. Use MobX related functions like [`reaction`](https://mobx.js.org/refguide/reaction.html), [`autorun`](https://mobx.js.org/refguide/autorun.html), [`when`](https://mobx.js.org/refguide/when.html), [`observe`](https://mobx.js.org/refguide/observe.html), or anything else that returns a disposer.\nReturns the generated disposer for early disposal.\n\nExample (TypeScript):\n\n```typescript\nimport { reaction } from \"mobx\"\nimport { observer, useComputed, useDisposable } from \"mobx-react-lite\"\n\nconst Name = observer((props: { firstName: string; lastName: string }) => {\n    const fullName = useComputed(() => `${props.firstName} ${props.lastName}`, [\n        props.firstName,\n        props.lastName\n    ])\n\n    // when the name changes then send this info to the server\n    useDisposable(() =>\n        reaction(\n            () => fullName,\n            () => {\n                // send this to some server\n            }\n        )\n    )\n\n    // render phase\n    return `Your full name is ${props.firstName} ${props.lastName}`\n})\n```\n","readmeFilename":"README.md","gitHead":"0052a83794e7a016127251fa3a78b8f70919ec4e","_id":"mobx-react-lite@2.0.0-test.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"fredyc","email":"fredy.c@seznam.cz"},"dist":{"integrity":"sha512-TXf0WbEo1GfNsvmrLNq4uWh3LEyvrC49SE0a8aFDFnyKxQgTVSncE9d/TtsxNwDBiEjsnlrxosUhD7mgAqLZFg==","shasum":"24f002c1eb631a4ebf8205bf2e4d05ccdf0f74ec","tarball":"http://registry-npm.ywwl.com/mobx-react-lite/download/mobx-react-lite-2.0.0-test.0.tgz","fileCount":314,"unpackedSize":420287,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc7uNvCRA9TVsSAnZWagAAPW8QAJpoURQiiXFaS9Fkb/nG\n6yr4wOha0c4d01ff7L2Wa/TjKEAxgOnwf4xGbJmkpS4OVftvinfDrquTCZVY\njaqpq0EmYR2gyoN6r1slJHXz6elGDHQuWrBXBz3thhrHd/Mp8MR1K1ukMDT9\n0NNVlG8bH6kHKArld51nkRULTKbopR6T8w7Fzj62aNqYwGb2K1kHouziP5f1\n53iUIgRafPm/QXTaQFAvNdkHAbFgmosw4U4dhIt/wfqDbAS0mLX25VUZNRkJ\nysn45mcdaXKKks/Jzrjgx04StO96sZNltXfbpWBrI4lRLW8PppZBFe/nfb87\n3t3oCP2GXktlMlIX1v7TAGREtVMNjcYfNXFeoaSFi9GlsUW17UJoBWlifAIj\nfP7PrybOYYfteIHjFQjRBDAgYSf/IN04iDapzmL1PzT0dAHFd0wK93OWT/BW\nUoDzJRAU7kWSeNzorNtPZ4GSds7W438yAAftA4juugeKDswxjSJCuM5I1pCp\nX1t92o6lQjfLRx5AUEmSKIffDjcrrX4EpTkcYaXkkzhOZt6/kbCPVqoh7VSR\nrj/qCLcwJNnoAB5YjNQ8XUsYi97GLiEFItKSlwXVi54NHC92MFsCyXYAYejc\nH913ht/KFJOTHghmjCK3c9u41NMAB6MZ305K8B1MEyj/5WGhQ32OZu20l7sa\n3YLT\r\n=avoO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEXj0ZEZ+z8ER156ypO1iIhwbIyJRbpQpJ9OXh2qDHXbAiEAx5nWYprgUvgLpR7foOSeGmWee9GEd8/W/PVrJ/1Ev74="}],"size":147539,"noattachment":false,"key":"/mobx-react-lite/-/mobx-react-lite-2.0.0-test.0.tgz"},"maintainers":[{"name":"fredyc","email":"fredy.c@seznam.cz"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mobx-react-lite_2.0.0-test.0_1559159662576_0.2326794806821777"},"_hasShrinkwrap":false,"publish_time":1559159662708,"_cnpm_publish_time":1559159662708,"dist-tags":{"alpha":"4.0.7-alpha","beta":"3.0.0-beta.1","experimental":"4.0.4-x1","latest":"5.1.2","next":"2.0.0-alpha.5"}}