use-cleared-memo
v1.4.3
Published
useClearedMemo(getFn, clearFn, deps, clearFnDeps)
Downloads
26
Maintainers
Readme
Are you building a hook or functional React component that needs to predictably clear and/or hydrate memoized values in an easy-to-use way? Opportunities are almost endless; no matter if you're subscribing to external state, initializing timers or intervals, or creating a new instance of some object every time deps change that eventually needs to be deconstructed, useClearedMemo
will be there for you to do the job.
useClearedMemo(getFn, clearFn, deps, clearFnDeps) ⇒ T
Kind: global function
Returns: T - The value to be memoized and cleared appropriately.
| Param | Type | Description | | --- | --- | --- | | getFn | function | Returns the memoized value that is to be cleared. | | clearFn | function | Clears the previously memoized value when the component unmounts or the deps change. | | deps | ReadonlyArray | Identities that the getFn depends on. When changed, the previously memoized value will be cleared and the getFn will be called to retrieve the new value. | | clearFnDeps | ReadonlyArray | Identities that the clearFn depends on. |
Authors
- Ludvig Aldén @ludvigalden