[feature request/question]
Consider a component that has a stateless functional component (SFC) as prop, e.g. like this:
<MyComponent component={(props) => <div>{props.title}</div>;} />
Using shallowCompare in shouldComponentUpdate of MyComponent would always return true, but there are cases when it makes sense to use shallowCompare on all props except those with SFCs, like in this issue in redux-form, which had this solution:
shouldComponentUpdate(nextProps) {
const propsWithoutComponent = { ...this.props }
const nextPropsWithoutComponent = { ...nextProps }
delete propsWithoutComponent.component
delete nextPropsWithoutComponent.component
return shallowCompare({ props: propsWithoutComponent }, nextPropsWithoutComponent)
}
While I have no idea how common this pattern is or will be, I saw that context is about to be added to shallowCompare and I thought maybe it would be possible to add an option to make shallowCompare ignore one or several props?
E.g. the signature could be like this instead:
function shallowCompare(instance, { nextProps, nextState, nextContext, propsToIgnore })
where propsToIgnore could be an array of string keys. (To avoid a breaking change, propsToIgnore could of course be added as the fifth argument instead, but this seems more robust to me.)
If this makes sense to you, I could have a go at a PR for this.
[feature request/question]
Consider a component that has a stateless functional component (SFC) as prop, e.g. like this:
Using
shallowCompareinshouldComponentUpdateofMyComponentwould always returntrue, but there are cases when it makes sense to useshallowCompareon all props except those with SFCs, like in this issue inredux-form, which had this solution:While I have no idea how common this pattern is or will be, I saw that
contextis about to be added toshallowCompareand I thought maybe it would be possible to add an option to makeshallowCompareignore one or several props?E.g. the signature could be like this instead:
where
propsToIgnorecould be an array of string keys. (To avoid a breaking change,propsToIgnorecould of course be added as the fifth argument instead, but this seems more robust to me.)If this makes sense to you, I could have a go at a PR for this.