Martin Konicek
Martin Konicek

Reputation: 40924

Compare objects in React Native

How can I check if two JavaScript values are the same?

If they are objects, I would like to compare them key-by-key recursively.

I'm looking for an existing function, not a way to write my own like described in this question: Object comparison in JavaScript.

Upvotes: 3

Views: 4470

Answers (3)

Namit Gupta
Namit Gupta

Reputation: 826

In react native >= 0.62.2 use,

import deepDiffer from `react-native/libraries/utilities/differ/deepDiffer`

deepDiffer(obj1, obj2) // true or false

Upvotes: 2

dB.
dB.

Reputation: 4770

Took a bit of Googling to find how to import deepDiffer.

import deepDiffer from 'react-native/lib/deepDiffer'

...

deepDiffer(obj1, obj2) // true or false

Upvotes: 2

Martin Konicek
Martin Konicek

Reputation: 40924

There's a function called deepDiffer which does this.

Upvotes: 5

Related Questions