Use deep equality
Closed this issue · 3 comments
dantehemerson commented
Could use deep equality to compare objects array in:
use-debounce/src/useDebounce.ts
Lines 4 to 6 in f135b40
xnimorz commented
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 })
}
dantehemerson commented
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.
xnimorz commented
We released it several days earlier. I'm going to add list of options to the README during this week.