A
A
Andrew2019-05-01 03:49:53
React
Andrew, 2019-05-01 03:49:53

Why after adding reselect the component is still updated when the old data arrives?

My code: https://codesandbox.io/s/n15060lny4
5cc8edcee483f812866785.png
When I click on noop, I add the same data but with a new link to the object, since the data is the same, the link should return the old one from the memoization of the reselect, and accordingly there should not be an update , but for some reason the component is updated exactly.
Simple example:

const selectData = createSelector(
  data => data,
  data => [...data]
)

// Должно быть true но возвращает false
console.log(selectData([{a:1}, {a:2}]) === selectData([{a:1}, {a:2}]))
<code>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-01
@undefined_title

This is the standard behavior of the library. By default, an identity check is performed:

function defaultEqualityCheck(a, b) {
  return a === b
}

The library API provides the ability to create a selector builder with custom comparison.
The official documentation has an example with deepEqual

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question