์์ ํ๋๋ฅผ ์ ํจ์ฑ ๊ฒ์ฌ ๋ ผ๋ฆฌ๋ฅผ ํฌํจํ๋ ์์ฒด ๊ตฌ์ฑ ์์๋ก ๋ํํฉ๋๋ค. ์
UsernameInput.js
class UsernameInput extends Component {
render() {
return this.props.form.getFieldDecorator(this.props.id, {
rules: [...]
})(InputComponent);
}
}
๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฌ๋ ์ด๊ฒ์ ์ฐ๋ฆฌ์ ํํ๋ก ์ฌ์ฉํ๊ณ ์ถ์ต๋๋ค.
// imports here
class CustomForm {
render() {
return (<Form>
<Form.Item>
<UsernameInput form={this.props.form} />
</Form.Item>
</Form>);
}
}
export default Form.create()(CustomForm);
FormItem.getControls ๊ฐ ๊ตฌ์ฑ ์์๋ฅผ ์ปจํธ๋กค๋ก ๊ฐ์งํ์ง ์๊ธฐ ๋๋ฌธ์ ์๋ํ์ง ์์ต๋๋ค. ๋ํผ๋ฅผ UsernameInput์ผ๋ก ๋ด ๋๋ค.
FormItem
๋ UsernameInput
๋ฅผ ๊ฐ์งํ๊ณ ๋ชจ๋ ์
๋ ฅ ์ปจํธ๋กค๋ก ์๋ํฉ๋๋ค. ์ค๋ฅ ๋ฉ์์ง, ํผ๋๋ฐฑ, ๋์๋ง ๋ฑ์ ํ์ํฉ๋๋ค.
FormItem
๋ด๋ถ์์ ์ปจํธ๋กค์ ์ฐพ์ ์ ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฒ์ ์ด๋ ต์ต๋๋ค. ์ฌ๊ธฐ์ ์กฐ์ธ (๊ตฌํ ๋ฐฉ๋ฒ)์ ๊ฒ์ ํ ์ ์์ต๋๊น?
์ปดํฌ๋ํธ๋ฅผ ํจ์๋ก ํธ์ถํ์ฌ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
CustomForm.js
// imports here
class CustomForm {
render() {
return (<Form>
<Form.Item>
{UsernameInput({ form: this.props.form })}
</Form.Item>
</Form>);
}
}
export default Form.create()(CustomForm);
๊ทธ๋ฌ๋ ์์ด๋์ด์ ๊ฐ๋ฐฉ์ ์ด๋ผ๋ฉด ๊ฐ๋ฅํ ํด๊ฒฐ์ฑ
์ FormItem
์ปจํ
์คํธ๋ฅผ ์ ์ํ๋ ๊ฒ์ด๋ฉฐ Input
๋ ์กด์ฌํ ๋ ์ค์ค๋ก ๋ฑ๋ก ํ ์ ์์ต๋๋ค. ์
FormItem.js
class FormItem extends Component {
static childContextTypes = {
registerControl: PropTypes.func
};
getChildContext() {
return { registerControl: this.registerControl };
}
registerControl(control) {
this.controls.push(control);
}
}
Input.js
class Input extends Component {
static contextTypes = {
registerControl: PropTypes.func
};
componentDidMount() {
if (this.context.registerControl) {
this.registerControl(this);
}
}
}
ํด๊ฒฐ์ฑ ์ ์ฐพ๋๋ก ๋ ธ๋ ฅํ๊ฒ ์ต๋๋ค.
@gaastonsr ์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก UsernameInput์ ๋ํ ์ ์ฒด ์ฝ๋๋ฅผ ํ์ ํ ์ ์์ต๋๊น?
@gaastonsr ๊ทํ์ ์๋ฃจ์ ์ ์ ๋ฅผ ๋ง์ด ๋์์ค๋๋ค!
์ฌ์ ํ ์ ํจํ ๋ฌธ์ ์ ๋๊น? ๋ฌธ๋งฅ ์ ์์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
์ค๋ [email protected] ์์ @gaastonsr ์ ํจ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ปจํ ์คํธ๋ฅผ ํ์ธํ๊ธฐ ์ํด ๋ชจ๋ ์์ ๊ตฌ์ฑ ์์๋ฅผ ์๊ตฌํ๋ ๊ฒ๋ณด๋ค ๋ ์ฐ์ํฉ๋๋ค.
์๋ ํ์ธ์ @gaastonsr. ๊ทํ์ ์ ์ / ํผ๋๋ฐฑ์ด ๋ง์์ ๋ค์์ต๋๋ค. Pull Request ๋ฅผ
์๋ ํ์ธ์ @gaastonsr, ์ฐ๋ฆฌ๋ ๊ทํ์ ์ ์ / ํผ๋๋ฐฑ์ ์ ์ ์ผ๋ก ๋์ํฉ๋๋ค.์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Pull Request ๋ฅผ ์ญ์์ค . Pull Request๋ฅผ ์ฌ๋ฐ๋ฅธ ๋ธ๋์น (๊ธฐ๋ฅ ๋ธ๋์น์ ์ ๊ธฐ๋ฅ, โโ๋ค๋ฅธ ๊ธฐ๋ฅ์ ๋ง์คํฐ ๋ธ๋์น)๋ก ๋ณด๋ด ์ฃผ์๊ณ , Pull Request
antd v4์์ ์๋ก์ด ์์ ๊ตฌ์ฑ ์์๋ฅผ ํ์ธํ์ญ์์ค. v3 ์์์ ๋จ์๊ฐ์ ์ ์ง๋์ง ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ปดํฌ๋ํธ๋ฅผ ํจ์๋ก ํธ์ถํ์ฌ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
CustomForm.js
๊ทธ๋ฌ๋ ์์ด๋์ด์ ๊ฐ๋ฐฉ์ ์ด๋ผ๋ฉด ๊ฐ๋ฅํ ํด๊ฒฐ์ฑ ์
FormItem
์ปจํ ์คํธ๋ฅผ ์ ์ํ๋ ๊ฒ์ด๋ฉฐInput
๋ ์กด์ฌํ ๋ ์ค์ค๋ก ๋ฑ๋ก ํ ์ ์์ต๋๋ค. ์FormItem.js
Input.js