add cmpRef util

This commit is contained in:
Vyrtsev Mikhail
2019-07-29 13:47:35 -05:00
committed by Umputun
parent 0d6ae9edd4
commit a9e4ce368d
+13
View File
@@ -0,0 +1,13 @@
import isEqual from 'lodash/isEqual';
/**
* Deeply compares two entities,
* and if they are equal, then first entity
* will be returned
*
* Useful when we deal with react objects
*/
export function cmpRef<T>(a: T, b: T): T {
if (isEqual(a, b)) return a;
return b;
}