xnimorz/use-debounce

Use deep equality

Closed this issue · 3 comments

Could use deep equality to compare objects array in:

function valueEquality<T>(left: T, right: T): boolean {
return left === right;
}

Hello @dantehemerson
You can define your own equality function:
https://github.com/xnimorz/use-debounce/blob/master/src/useDebounce.ts#L11

So, you can call this hook with custom equalityFn

// suggest we defined deepEqual somewhere 

const equalityFn = (prev, next) => {
  return deepEqual(prev, next);
};

function MyComponent() {
  const [ state, setState ] = useState({foo: 'bar'});
   const [value] = useDebounce(state, 200, { equalityFn })
}

It's true, I had not noticed.
Maybe we could add the list of options to the README?.
If you want, I could help with this.

We released it several days earlier. I'm going to add list of options to the README during this week.