{"name":"use-memo-one","version":"1.1.2","description":"useMemo and useCallback but with a stable cache","keywords":["memoization","react","useMemo","useCallback","memoize-one"],"main":"dist/use-memo-one.cjs.js","module":"dist/use-memo-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.0 || ^17.0.0"},"devDependencies":{"@babel/core":"^7.5.0","@babel/preset-env":"^7.5.2","@babel/preset-flow":"^7.0.0","@babel/preset-react":"^7.0.0","babel-core":"^6.26.3","babel-eslint":"^10.0.2","babel-jest":"^24.8.0","enzyme":"^3.10.0","enzyme-adapter-react-16":"^1.14.0","eslint":"^6.0.1","eslint-config-airbnb":"^17.1.1","eslint-config-prettier":"^6.0.0","eslint-plugin-flowtype":"^3.11.1","eslint-plugin-import":"^2.18.0","eslint-plugin-jest":"^22.7.2","eslint-plugin-jsx-a11y":"^6.2.3","eslint-plugin-prettier":"^3.1.0","eslint-plugin-react":"^7.14.2","eslint-plugin-react-hooks":"^1.6.1","flow-bin":"^0.102.0","jest":"^24.8.0","jest-watch-typeahead":"^0.3.1","prettier":"^1.18.2","react":"^16.8.6","react-dom":"^16.8.6","rimraf":"^2.6.3","rollup":"^1.16.7","rollup-plugin-babel":"^4.3.3","rollup-plugin-commonjs":"^10.0.1","rollup-plugin-replace":"^2.2.0","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-memo-one.cjs.js.flow","prepublish":"yarn run build"},"gitHead":"d242954cd7ce530f0f76ac947221f0faa33b2c0a","bugs":{"url":"https://github.com/alexreardon/use-memo-one/issues"},"homepage":"https://github.com/alexreardon/use-memo-one#readme","_id":"use-memo-one@1.1.2","_nodeVersion":"10.15.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-u2qFKtxLsia/r8qG0ZKkbytbztzRb317XCkT7yP8wxL0tZ/CzK2G+WWie5vWvpyeP7+YoPIwbJoIHJ4Ba4k0oQ==","shasum":"0c8203a329f76e040047a35a1197defe342fab20","tarball":"http://registry-npm.ywwl.com/use-memo-one/download/use-memo-one-1.1.2.tgz","fileCount":11,"unpackedSize":15710,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgDgsHCRA9TVsSAnZWagAAUOwP/1/azb3FvTtXb9Opvu/V\nkCaGVzSbt0bkbD3wzsU5xPHAjBLybFer5tOc0I5GW4cLIWnvdbiXdBb9IqKC\nVjA5mCUJ9T2aTRGIcl1b8WiowHXjnjlqbIPMVndqNkrjBeJzgGfsz1b/VGAR\natiDA+7UAAeEp3yW68bMlk6KjRIwk5YVvpZU7GQPi5YT8E2BbodLBz6Hwm7W\nNLVQVwf/8g/rS2qv7+p2XetX1X9Dqz4a79rqL2UrqjSOjYMEN0ssWezUW01u\n1MYU6TF1NrPgTextbYNxnXd189aJA1sOkGF3OxXQi9YmwFQE6W8UrRBhWZTo\nl/D3JR+QR1vZ7At1uakWu4uMqkSN1pGp5SKOvQzx3nhYYdgJbIXeHjB6adFs\nN4rSTScB16qV6Q2izydaQumDjOa8//nvRW5gk9FnAw4NcOOAdWPV/4LBbJvT\nayGWc/eSay6HKKT2m1WxI51nIssEVx9wQbehEToGa+f5Y6GjcJXuRH/7zKlN\nueZDGBsS76/eHTZ2yrdlNEb/HK2VyhLuJyT14kTl4I2t4uDZZ2q/py3AB0+S\nRaUQicnw+ve+pxgNA5OTepUulJ5nGwy0FVeJ9lVUnAcw8aOkgtMGEuoKBbpF\nXSqNet2AyZePoa1GWfUx9CJnOFls0vdnhCJcqo5Zujb6LztYiwgXD9ZNnyI6\nYF1J\r\n=7L7F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAR2yzCwl/eVWdV7/56PSicJpPNHnM8H6s4x8ycppYMCAiBKU0IUAN/ysxcxW9lNN7EWcY5hPa0EKlwyA1cOTW9jlw=="}],"size":5232,"noattachment":false,"key":"/use-memo-one/-/use-memo-one-1.1.2.tgz"},"_npmUser":{"name":"alexreardon","email":"alexreardon@gmail.com"},"directories":{},"maintainers":[{"name":"alexreardon","email":"alexreardon@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/use-memo-one_1.1.2_1611533063213_0.5021770643806425"},"_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":1611533063324,"_cnpm_publish_time":1611533063324,"dist-tags":{"beta":"1.1.0-beta.0","latest":"1.1.3"}}