liveBook · Manning

Equality

As explained in React in Depth

The strict equality operator (===) compares two JavaScript values without type conversion and returns true only when their types and equality conditions match.

The strict equality operator (===) compares JavaScript values without type conversion. Primitive values match when they represent the same data; objects, arrays, and functions match only when both references identify the same object. section 3.3

React uses this referential form of strict equality when checking dependency arrays. A newly created object or array can therefore count as changed even when its contents look identical, while a stable reference does not. section 3.3 section 3.4

The comparison rules differ by value category:

  • Primitives compare by represented data, so 2 === 1 + 1 evaluates to true. section 3.3
  • Different object or array literals do not match: {} !== {} and [] !== []. section 3.3
  • Unlike ==, === does not convert types, so "1" == 1 but strict equality requires identical types. section 3.3

Dependency identity in React

When a hook dependency array contains [id], React reruns the hook when id changes according to strict equality. An object or array dependency must retain the same reference to be considered unchanged. section 3.3

How React in Depth covers it

How deep it goes
Explains primitive versus object comparison and React dependency effects, without descending into equality algorithm internals.
Examples
Uses "1" == 1, 2 === 1 + 1, {} !== {}, [] !== [], and useEffect dependency arrays.
What it assumes
Assumes React dependency-array context while defining JavaScript primitive, object, and type-comparison behavior.
What you can do after
Evaluate React dependency changes by distinguishing equal primitive data from stable or newly created object references.
How it connects
Connects strict equality with referential equality, dependency arrays, React hooks, memoization, and rerender optimization.

Also explained in

Compare how 4 books explain equality →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.