react-decorators
react-decorators copied to clipboard
DefaultProps
How can you specify defaultProps on the ownee class?
Decorators hide static properties..
Sorry, but I don’t understand your answer. I’d like to know how I can define propTypes and defaultProps on the component that is being decorated?
In general you define default properties and their types like so:
class MyComponent {
static propTypes: {
message: PropTypes.string.isRequired
};
static defaultProps: {
message: 'Welcome!'
};
render() {
return <div>{this.props.message}</div>;
}
}
...but the problem is, if you wrap this class into a higher-level component, HOC will hide static properties of the ownee class.
Does that mean that it is useless to have propTypes
and defaultProps
defined on the ownee class? And how can we work around this without too much hacking? After all, the checks on propTypes and default provided values are quite important in many cases.
@Frikki Got any solution for accessing the props?? Any work around
class MyComponent {
props: {
message: 'Welcome!'
};
}