【发布时间】:2022-01-13 14:40:04
【问题描述】:
这是我的代码
const Input = props => {
return (
<React.Fragment>
<label>{props.label}</label>
<input
className="input"
type={props.type}
placeholder={props.placeholder}
></input>
</React.Fragment>
);
};
我想从我的应用程序中接收来自其他组件的数据。但它只适用于第一次 props 调用后的另一行代码:
const Input = (props: { label: boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null | undefined; type: string | (string & {}) | undefined; placeholder: string | undefined; }) => {
return (
<React.Fragment>
<label>{props.label}</label>
<input
className="input"
type={props.type}
placeholder={props.placeholder}
></input>
</React.Fragment>
);
};
有没有办法让这段代码看起来更漂亮?
谢谢!
【问题讨论】:
-
这个问题最好在这里问:codereview.stackexchange.com
-
你是如何将 props 传递给组件的?
-
像这样传递道具:
标签: reactjs typescript frontend