use-memoize
v1.1.0
Published
useMemoize hook for React
Downloads
2
Readme
use-memoize
useMemoize hook for React
Install
npm install --save use-memoize
Usage
import React from 'react'
import { useMemoize } from 'use-memoize'
const fn = (num: number) => {
console.log('exec', num)
return 2 * num
}
class Example extends React.Component {
const [count, setCount] = React.useState(0)
const memo = useMemoize(fn)
memo(count)
return (
<div>
<span>Create React Library Example 😄</span>
<span>count * 2: {memo(count)}</span>
<button onClick={() => setCount(prevState => prevState += 1)}>Incr</button>
<button onClick={() => setCount(prevState => prevState -= 1)}>Decr</button>
</div>
)
}
License
MIT © mbarinov