mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
Move form's wrapped component instantiation to constructor
This commit is contained in:
parent
9e959b96c6
commit
41b585adfa
1 changed files with 18 additions and 7 deletions
|
@ -35,6 +35,13 @@ import { withDocument } from 'meteor/vulcan:core';
|
|||
|
||||
class FormWrapper extends PureComponent {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
// instantiate the wrapped component in constructor, not in render
|
||||
// see https://reactjs.org/docs/higher-order-components.html#dont-use-hocs-inside-the-render-method
|
||||
this.FormComponent = this.getComponent();
|
||||
}
|
||||
|
||||
// return the current schema based on either the schema or collection prop
|
||||
getSchema() {
|
||||
return this.props.schema ? this.props.schema : Utils.stripTelescopeNamespace(this.props.collection.simpleSchema()._schema);
|
||||
|
@ -108,13 +115,7 @@ class FormWrapper extends PureComponent {
|
|||
};
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
// prevent extra re-renderings for unknown reasons
|
||||
// re-render only if the document selector changes
|
||||
return nextProps.slug !== this.props.slug || nextProps.documentId !== this.props.documentId;
|
||||
}
|
||||
|
||||
render() {
|
||||
getComponent() {
|
||||
|
||||
// console.log(this)
|
||||
|
||||
|
@ -181,6 +182,16 @@ class FormWrapper extends PureComponent {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
// prevent extra re-renderings for unknown reasons
|
||||
// re-render only if the document selector changes
|
||||
return nextProps.slug !== this.props.slug || nextProps.documentId !== this.props.documentId;
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.FormComponent;
|
||||
}
|
||||
}
|
||||
|
||||
FormWrapper.propTypes = {
|
||||
|
|
Loading…
Add table
Reference in a new issue