Re-computes when parameter has not changed
Hi there, I am having trouble with my reselector always being re-computed. Below I have a stripped down example, that re-computes everytime.
I am using this in my makeMapDispatchToProps function of my container. I am unsure why the console.log message gets printed everytime even though the getImageElementId returns the same string each time.
const getImageElementId = (_, props) => {
return props.image.imageElementId; // props.image is an immutable record. imageElementId is a string
}
export const makeGetImageElementId = () => {
return createSelector(
getImageElementId,
(imageElementId) => {
console.log(`--makeGetImageElementId selector runs`);
return imageElementId;
}
);
};
Is there anything immediately apparent that I've done wrong, or am I testing for re-computation incorrectly (i.e. looking for the console.log output)?
Thank you very much
Hey ericj17, if you can produce a runnable demonstration of the problem you are having then I'll be happy to take a look at it for you.
Thanks ellbee, it was working after trying to build a runnable demo of the 'issue'. Went back to my original project code and figured out the problem was because I was calling makeGetImageElementId in the wrong location.
Below is the error I made, as shown in the context of your doc's example.
const makeMapStateToProps = () => {
const getVisibleTodos = makeGetVisibleTodos()
const mapStateToProps = (state, props) => {
//<-- I was incorrectly calling getVisibleTodos = makeGetVisibleTodos() here, instead of the above correct location
return {
todos: getVisibleTodos(state, props)
}
}
return mapStateToProps
}