Closed dminkovsky closed 8 years ago
Try adding it directly to the wrapped component.
Something like this:
const WrappedComponent = validation(strategy)(Component);
WrappedComponent.prototype.componentDidMount = function componentDidMount() {
this.validate();
}
export default WrappedComponent;
Duh of course. JavaScript! Thanks.
суббота, 19 декабря 2015 г. пользователь Clint Ayres написал:
Try adding it directly to the wrapped component.
Something like this:
const WrappedComponent = validation(strategy)(Component);WrappedComponent.prototype.componentDidMount = function componentDidMount() { this.validate(); }export default WrappedComponent;
— Reply to this email directly or view it on GitHub https://github.com/jurassix/react-validation-mixin/issues/63#issuecomment-166023642 .
Motivation: validating props before the a component mounts so that errors are available on first render.
I tried:
but that failed because the validator component, a parent of my wrapped component, had not mounted yet so its
refs
was empty.I've thought of some workarounds for this, but nothing really stuck out as great. Am I missing something?
I understand there's a bit of a chicken/egg problem here. Would it be possible to add a configuration to the top-level factory (the one that accepts the strategy) to make it perform this initial validation?