Skip to content

Commit

Permalink
refactor(react-toolkit-form): remove use of componentWillUpdate
Browse files Browse the repository at this point in the history
refactor(react-toolkit-form): remove use of componentWillUpdate
  • Loading branch information
guillaume-chervet committed May 27, 2020
2 parents 1048201 + 9aed3d6 commit b7354f2
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions packages/Form/core/src/FieldForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function renderedChildren(children, wrapper, message, messageType) {
return null;
}

const newRenderedChildren = React.Children.map(children, child => {
return React.Children.map(children, child => {
// create a copy that includes addtional property values
// as needed

Expand All @@ -43,7 +43,7 @@ function renderedChildren(children, wrapper, message, messageType) {
child.props.children,
wrapper,
message,
messageType
messageType,
);
if (subChildren != null) {
props.children = subChildren;
Expand All @@ -65,7 +65,6 @@ function renderedChildren(children, wrapper, message, messageType) {
}
return child;
});
return newRenderedChildren;
}

class FieldForm extends Component {
Expand All @@ -83,16 +82,6 @@ class FieldForm extends Component {
};
}

componentWillReceiveProps(nextProps) {
const { forceDisplayMessage } = this.props;
if (forceDisplayMessage !== nextProps.forceDisplayMessage) {
const memory = this.captureMemory();
this.setState({
memory,
});
}
}

onChange() {
const { hasChange } = this.state;
if (!hasChange) {
Expand All @@ -111,10 +100,13 @@ class FieldForm extends Component {
}

onFocus() {
const memory = this.captureMemory();
const { message, messageType } = this.props;
this.setState({
hasFocus: true,
memory,
memory: {
message,
messageType,
},
});
}

Expand All @@ -140,28 +132,20 @@ class FieldForm extends Component {
};
}

captureMemory() {
const { message, messageType } = this.props;
return {
message,
messageType,
};
}

render() {
const { children } = this.props;
const { message, messageType } = this.getInfo();
const childrenCloned = renderedChildren(
children,
this,
message,
messageType
messageType,
);
const { className, classModifier } = this.props;
const subComponentClassName = ClassManager.getComponentClassName(
className,
classModifier,
defaultClassName
defaultClassName,
);
return <div className={subComponentClassName}>{childrenCloned}</div>;
}
Expand Down

0 comments on commit b7354f2

Please sign in to comment.