{"repo":"andywer/use-inline-memo","free":true,"listed":false,"github":"https://github.com/andywer/use-inline-memo","clone":"git clone https://github.com/andywer/use-inline-memo.git","description":"⚛️ React hook for memoizing values inline anywhere in a component","language":"TypeScript","stars":164,"topics":["reactjs","react","react-hooks","memoization"],"license":null,"category":"ui-components","readme_excerpt":"⚛︎ use-inline-memo React hook for memoizing values and callbacks anywhere in a component. Like other hooks, you can call React.useMemo() and React.useCallback() only at the top of your component function and not use them conditionally. Inline memos let us memoize anywhere without the restrictions that apply to the usage of hooks! Installation Usage Everytime you want to memoize a value, call memo.X() with an identifier X of your choice. This identifier will be used to map the current call to values memoized in previous component renderings. Calling useInlineMemo() without arguments should work in all ES2015+ runtimes as it requires the ES2015 Proxy . If you need to support older browsers like the Internet Explorer, you will have to state the memoization keys up-front: When not run in production, there is also a check in place to prevent you from accidentally using the same identifier for two different values. Calling memo.X() with the same X twice during one rendering will lead to an error. Use cases Event listeners Inline memoizers are perfect to define simple one-line callbacks in-place in the JSX without sacrificing performance. style props & other objects Using inline style props is oftentimes an express ticket to unnecessary re-renderings as you will create a new style object on each rendering, even though its content will in many cases never change. You don't need to memoize every style object of every single DOM element, though. Use it whenever you pass an object to a ","default_branch":null,"files":null,"tree":[],"storefront":"/r/andywer","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/andywer/use-inline-memo/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}