web icon indicating copy to clipboard operation
web copied to clipboard

useDeepCompareMemo hook

Open fengkx opened this issue 3 years ago • 0 comments

New Features

useDeepCompareMemo hook

What is the new or updated feature that you are suggesting?

A deep compare version of useMemo

Why should this feature be included?

To memo a value with deep compare

import { useDeepCompareEffect } from '@react-hookz/web'
import { useState } from 'react'

export function useDeepCompareMemo<T> (
  factory: () => T,
  deps: React.DependencyList
) {
  const [state, setState] = useState(factory)
  useDeepCompareEffect(() => {
    setState(() => factory())
  }, deps)
  return state
}

Here is a poc impl

fengkx avatar Jul 12 '22 08:07 fengkx