the life cycle componentWillMount of react is changed to react hooks. Where is the code in the life cycle of componentWillMount () written?
for example, the following example:
import React from "react";
import ReactDOM from "react-dom";
import { createForm, formShape } from "rc-form";
class Form extends React.Component {
static propTypes = {
form: formShape,
};
componentWillMount() {
this.nameDecorator = this.props.form.getFieldDecorator("name", {
initialValue: "",
rules: [{
required: true,
message: "What\"s your name?",
}],
});
}
onSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((error, values) => {
if (!error) {
console.log("ok", values);
} else {
console.log("error", error, values);
}
});
};
onChange = (e) => {
console.log(e.target.value);
}
render() {
const { getFieldError } = this.props.form;
return (
<form onSubmit={this.onSubmit}>
{this.nameDecorator(
<input
onChange={this.onChange}
/>
)}
<div style={{ color: "red" }}>
{(getFieldError("name") || []).join(", ")}
</div>
<button>Submit</button>
</form>
);
}
}
const WrappedForm = createForm()(Form);
ReactDOM.render(<WrappedForm />, document.getElementById("__react-content"));