0
이 코드를 건조하는 것이 더 좋은지 궁금한 점이 있습니까? 당신은 {{select}} and {{selectAsync}}
와 jsx 부분에서 그들을 렌더링 할 수DRY jsx 렌더링 방법
let createElement = function(Component) {
return (
<Component onChange={(val) => {
onChange(val);
callback(val);
}}
value={value}
{...rest}
/>
);
};
당신이
let selectAsync = createElement(Select.Async);
let select = createElement(Select);
을 수행 할 수 있습니다 소품은 ...
render() {
const { input: { value, onChange }, callback, async, ...rest } = this.props;
if (async) {
return (
<Select.Async
onChange={(val) => {
onChange(val);
callback(val);
}}
value={value}
{...rest}
/>
);
}
return (
<Select
onChange={(val) => {
onChange(val);
callback(val);
}}
value={value}
{...rest}
/>
);
}
코드가 작동하고 그것을 개선/검토하려면 [codereview.se]에 게시 할 수 있습니다. 먼저 [좋은 질문을하는 법은 무엇입니까?] ( – Tushar
) [React/(http://stackoverflow.com/questions/29875869/react-jsx-dynamic-component-name) – Whymarrh
@ Tushar 덕분에 다음 번에 기억하겠습니다. –