I would like to propose a small addition to the propTypes.
I and a few others have encountered issues when using Redux connect to inject information from a store. See:
https://github.com/yannickcr/eslint-plugin-react/issues/553
I was wandering if maybe adding an ".isInjected" to PropType would make sense? It could work similar to ".isRequired" where it can be chained to any to any datatype. However, where isRequired validates a value is passed, isInjected validates a value is NOT passed.
Example:
MyComponent.propTypes = {
optionalBool: React.PropTypes.bool,
requiredBool: React.PropTypes.bool.isRequired,
injectedBool: React.PropTypes.bool.isInjected,
}
I wanted to vet the idea before bothering with a pull request.
We don't currently plan to make changes to PropTypes but you are welcome to create your own package implementing something like this.
Personally I would suggest defining common propTypes separately from "injected" ones. Then use both:
const propTypes = {
foo: PropTypes.string
};
const injectedPropTypes = {
bar: PropTypes.string
};
Comment.propTypes = {
...propTypes,
...injectedPropTypes
};
const ConnectedComment = connect(
mapStateToProps
)(Comment);
ConnectedComment.propTypes = propTypes;
export default ConnectedComment;
I hope it helps!
Most helpful comment
We don't currently plan to make changes to PropTypes but you are welcome to create your own package implementing something like this.
Personally I would suggest defining common propTypes separately from "injected" ones. Then use both:
I hope it helps!