M
M
Max Zhukov2018-08-24 11:48:20
React
Max Zhukov, 2018-08-24 11:48:20

Why is reselect not working?

selector

import { createSelector } from 'reselect';

const getGames = state => state.game.games;

export const gamesSelector = createSelector(getGames, games => games);

container
import { gamesSelector } from '../../../selectors';


const mapStateToProps = state => ({
  games: gamesSelector(state),
});

When the data of one game object changes, all the games components are re-rendered.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-24
@MaksZhukov

What did you expect? You're creating a useless selector that doesn't select anything, but simply passes the games object through. Then, you pass this object in its entirety to connect. Naturally, when it changes, your component will re-render all child components in a chain.
Do a shouldComponentUpdate check in the Game components and compare the incoming objects:

shouldComponentUpdate(nextProps) {
  return nextProps.game !== this.props.game;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question