{"name":"use-memo-one","version":"0.0.2","description":"useMemo and useCallback, but without cache invalidation","main":"dist/memoize-one.cjs.js","module":"dist/memoize-one.esm.js","sideEffects":false,"author":{"name":"Alex Reardon","email":"alexreardon@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alexreardon/use-memo-one.git"},"peerDependencies":{"react":"^16.8.6"},"devDependencies":{"@babel/core":"^7.4.0","@babel/preset-env":"^7.4.2","@babel/preset-flow":"^7.0.0","@babel/preset-react":"^7.0.0","babel-core":"^6.26.3","babel-eslint":"^10.0.1","babel-jest":"^24.6.0","enzyme":"^3.9.0","enzyme-adapter-react-16":"^1.11.2","eslint":"^5.16.0","eslint-config-airbnb":"^17.1.0","eslint-config-prettier":"^4.1.0","eslint-plugin-flowtype":"^3.4.2","eslint-plugin-import":"^2.16.0","eslint-plugin-jest":"^22.4.1","eslint-plugin-jsx-a11y":"^6.2.1","eslint-plugin-prettier":"^3.0.1","eslint-plugin-react":"^7.12.4","eslint-plugin-react-hooks":"^1.6.0","flow-bin":"^0.95.1","jest":"^24.6.0","jest-watch-typeahead":"^0.2.1","prettier":"^1.16.4","react":"^16.8.6","react-dom":"^16.8.6","rimraf":"^2.6.3","rollup":"^1.7.4","rollup-plugin-babel":"^4.3.2","rollup-plugin-commonjs":"^9.2.2","rollup-plugin-replace":"^2.1.1","rollup-plugin-uglify":"^6.0.2"},"config":{"prettier_target":"*.{js,jsx,md,json} src/**/*.{js,jsx,md,json} test/**/*.{js,jsx,md,json}"},"scripts":{"validate":"yarn run lint && yarn run typecheck","test":"jest","typecheck":"flow check","prettier:check":"yarn prettier --debug-check $npm_package_config_prettier_target","prettier:write":"yarn prettier --write $npm_package_config_prettier_target","lint:eslint":"eslint src test","lint":"yarn lint:eslint && yarn prettier:check","build":"yarn run build:clean && yarn run build:dist && yarn run build:flow","build:clean":"rimraf dist","build:dist":"rollup -c","build:flow":"echo \"// @flow\n\nexport * from '../src';\" > dist/use-memoize-one.cjs.js.flow","prepublish":"yarn run build"},"gitHead":"f986056f7f4b2bb6f6b05f94b97c5e58fb67cf54","bugs":{"url":"https://github.com/alexreardon/use-memo-one/issues"},"homepage":"https://github.com/alexreardon/use-memo-one#readme","_id":"use-memo-one@0.0.2","_npmVersion":"6.1.0","_nodeVersion":"8.11.3","_npmUser":{"name":"alexreardon","email":"alexreardon@gmail.com"},"dist":{"integrity":"sha512-aVH6yaT2R6Jyj3QJ93KJ2zncE7WE5YG4SxJc1NAJWUDjnSePXtlu9MIS7KgN/uM5S9tMLg2dxFG6dqbvGhlMjQ==","shasum":"0612a7684cd84fb55956fd27f34d0210c77c5d2c","tarball":"http://registry-npm.ywwl.com/use-memo-one/download/use-memo-one-0.0.2.tgz","fileCount":46,"unpackedSize":453720,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcoqQ4CRA9TVsSAnZWagAA/1QP/1f7shPe0QwZeVpsavMy\noYK8Kp5x7x8YBazCqzchH/NNseYgOK4rz7AT0Fm9BpUfMDDXbSBrMyKIg5Xk\nI/UyJHEK9lRZJS16q2Pbxk9MWEYUq3oTMmSe8a7df8cwTu+K3ndIhAHlI0cJ\nFCCDYgm6PLTJgKQSW4hGSdORRTOyVuX06rIAVC8nhefwuM3N8+cZFOVua9Ts\nNRFjAEVe7aOsg2F9a8H1vcAZvolFcZNpbCSf7DXYRjZfiSvhC6MwolvoyG3g\n9b+HRsSFiL22LIZKSAlTO7hPwJ5MdQuCwICWSodokQ44KSLDWcal1+2YdDI/\nH5Un+zOdTY83RQbUGAkhF4smpCNO58+Hg7ND5G8MufgTW6fPFdjNpvTSEL0b\nSNswxzyKhaxrLxgtMoXvsIbajaK/njxeo3p+hCEEVa7NuRqDMn6ZtW/5kKtd\nGBR7JQggkY5OH/ma5q10KL9M9xafU8Ln+kKnR4txe4tx2laqjkW+SJ1OyFjS\n4v5jUdlYDV/d0gAH64OTud63iHGsYJC2Q4W6YHOQ2xwKXQM427spRkdpKv9Z\n6MkNlca0RTenGCDPQ1kHdjD6ez6WdK2WXATAaR0eEVjY8k3JNNAYn7fiAMwE\nI0mdGn6rPJmxnFLk4rb6sX23KafGfPWn33LBZCPH20zX4uCipNId64YFx7uY\n6+XS\r\n=wRgE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE6tsEK9/ZdmFWwxlvFmPNpJWvpU8e0C5w2gAXjx8dv8AiBjmsTAJZAB1fDMvJN8/0/Opro5aCWVdNj6sbSjBnzQsg=="}],"size":118102,"noattachment":false,"key":"/use-memo-one/-/use-memo-one-0.0.2.tgz"},"maintainers":[{"name":"alexreardon","email":"alexreardon@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-memo-one_0.0.2_1554162743355_0.7639843062941196"},"_hasShrinkwrap":false,"readme":"# useMemoOne\n\n[`useMemo`](https://reactjs.org/docs/hooks-reference.html#usememo) and [`useCallback`](https://reactjs.org/docs/hooks-reference.html#usecallback) with a stable cache (semantic guarantee)\n\n[![Build Status](https://github.com/alexreardon/use-memo-one/actions?query=workflow%3AValidate)](https://github.com/alexreardon/use-memo-one/workflows/Validate/badge.svg)\n[![npm](https://img.shields.io/npm/v/use-memo-one.svg)](https://www.npmjs.com/package/use-memo-one)\n[![dependencies](https://david-dm.org/alexreardon/use-memo-one.svg)](https://david-dm.org/alexreardon/use-memo-one)\n[![min](https://img.shields.io/bundlephobia/min/use-memo-one.svg)](https://bundlephobia.com/result?p=use-memo-one)\n[![minzip](https://img.shields.io/bundlephobia/minzip/use-memo-one.svg)](https://bundlephobia.com/result?p=use-memo-one)\n\n## Background\n\n`useMemo` and `useCallback` cache the most recent result. However, this cache can be destroyed by `React` when it wants to:\n\n> You may rely on useMemo as a performance optimization, **not as a semantic guarantee**. In the future, **React may choose to “forget” some previously memoized values** and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without useMemo — and then add it to optimize performance. [- React docs](https://reactjs.org/docs/hooks-reference.html#usememo)\n\n`useMemoOne` and `useCallbackOne` are `concurrent mode` safe alternatives to `useMemo` and `useCallback` **that do provide semantic guarantee**. What this means is that you will always get the same reference for a memoized value so long as there is no input change.\n\nUsing `useMemoOne` and `useCallbackOne` will consume more memory than `useMemo` and `useCallback` in order to provide a stable cache. `React` can release the cache of `useMemo` and `useCallback`, but `useMemoOne` will not release the cache until it is garbage collected.\n\n## Install\n\n```bash\n# npm\nnpm install use-memo-one --save\n# yarn\nyarn add use-memo-one\n```\n\n## Usage\n\n```js\nimport { useMemoOne, useCallbackOne } from 'use-memo-one';\n\nfunction App(props) {\n  const { name, age } = props;\n  const value = useMemoOne(() => ({ hello: name }), [name]);\n  const getAge = useCallbackOne(() => age, [age]);\n\n  // ...\n}\n```\n\n### Aliased imports\n\nYou can use this `import` style drop in replacement for `useMemo` and `useCallback`\n\nThis style also plays very well with [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks).\n\n```js\nimport { useMemo, useCallback } from 'use-memo-one';\n```\n\n⚠️ The aliased exports `useMemo` and `useCallback` will only work if you use _only_ `use-memo-one` and will clash if you also use `useMemo` or `useCallback` from `react`\n\n```js\nimport { useMemo, useCallback } from 'react';\n// ❌ naming clash\nimport { useMemo, useCallback } from 'use-memo-one';\n```\n\n## API\n\nSee [`useMemo`](https://reactjs.org/docs/hooks-reference.html#usememo) and [`useCallback`](https://reactjs.org/docs/hooks-reference.html#usecallback)\n\n## Linting\n\n`useMemo` and `useCallback` have fantastic linting rules with auto fixing in the [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) package. In order to take advantage of these with `useMemoOne` and `useCallbackOne`, structure your import like this:\n\n```js\nimport { useMemo, useCallback } from 'use-memo-one';\n// Or your can alias it yourself\nimport {\n  useMemoOne as useMemo,\n  useCallbackOne as useCallback,\n} from 'use-memo-one';\n\nfunction App() {\n  const [isActive] = useState(false);\n\n  const onClick = useCallback(() => {\n    console.log('isActive', isActive);\n\n    // the input array will now be correctly checked by eslint-plugin-react-hooks\n  }, [isActive]);\n}\n```\n\n## [`eslint`](https://eslint.org/) rules\n\nHere are some `eslint` rules you are welcome to use\n\n```js\nmodule.exports = {\n  rules: {\n    // ...other rules\n\n    'no-restricted-imports': [\n      'error',\n      {\n        // If you want to force an application to always use useMemoOne\n        paths: [\n          {\n            name: 'react',\n            importNames: ['useMemo', 'useCallback'],\n            message:\n              '`useMemo` and `useCallback` are subject to cache busting. Please use `useMemoOne`',\n          },\n          // If you want to force use of the aliased imports from useMemoOne\n          {\n            name: 'use-memo-one',\n            importNames: ['useMemoOne', 'useCallbackOne'],\n            message:\n              'use-memo-one exports `useMemo` and `useCallback` which work nicer with `eslint-plugin-react-hooks`',\n          },\n        ],\n      },\n    ],\n  },\n};\n```\n","publish_time":1554162743476,"_cnpm_publish_time":1554162743476,"dist-tags":{"beta":"1.1.0-beta.0","latest":"1.1.3"}}