Skip to content

createMemo

Category
Export Size
109 B
Last Changed
5 days ago

Turn a pure function into a memoising hook.

Demo

Usage

tsx
import { 
createMemo
} from '@reause/shared'
// called once, at module scope: the returned function is a hook const
useFullName
=
createMemo
((
first
: string,
last
: string) => `${
first
} ${
last
}`)
function
Profile
({
first
,
last
}: {
first
: string,
last
: string }) {
const
fullName
=
useFullName
(
first
,
last
)
return <
span
>{
fullName
}</span>
}

Type Declarations

ts
export function createMemo<T extends (...args: any) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>

Source

Source · Demo · react-use

Contributors

hairyf

Changelog

v0.1.6 on
56de4 - feat(shared): add createMemo (#930)

Released under the MIT License. v0.1.8