-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 Failed propType #6
Comments
When you use the When you then set Instead, use an class Info extends React.Component {
render() {
return (
<InfoComponent data={this.props.data}/>
);
}
}
Info.displayName = 'Info';
Info.propTypes = {
data: React.PropTypes.object.isRequired
};
@connect(state => ({
data: state.info
}))
export default InfoContainer extends React.Component {
render() {
return (
<Info {...this.props} />
)
}
} Or, you could probably do this (which is less extensible) @connect(state => ({
data: state.info
}))
export default InfoContainer extends Info {} |
Don't use inheritance please :-). I have never seen a justifiable case for it in React. class Info extends React.Component {
render() {
return (
<InfoComponent data={this.props.data}/>
);
}
}
Info.displayName = 'Info';
Info.propTypes = {
data: React.PropTypes.object.isRequired
};
export default connect(state => ({
data: state.info
}))(Info) |
How about using static propTypes inside the connected component? @connect(state => ({
data: state.info
}))
export default class Info extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired
}
render() {
return (
<InfoComponent data={this.props.data}/>
);
}
} |
@badtant A fix I just discovered, which allows you to use the decorator: @connect(state => ({
data: state.info
}))
class Info extends React.Component {
render() {
return (
<InfoComponent data={this.props.data}/>
);
}
}
Info.WrappedComponent.displayName = 'Info';
Info.WrappedComponent.propTypes = {
data: React.PropTypes.object.isRequired
};
export default Info; Note the use of the static property |
@blesswinsamuel In regards to your example using static propTypes... EDIT:
|
Hi, I'm using the connector to a ES6 class. I get my data but a warning on the propType. "Warning: Failed propType: Required prop
data
was not specified inHome
. Check the render method ofRouter
."I tried enabling es7.classProperties and move to static propTypes = ... That got rid of the warning but I rather stay on ES6 and only the ES7 features that i really want (like es7.decorators). Any ideas?
The text was updated successfully, but these errors were encountered: