反应,
您好我需要使用props更改const组件。
我该怎么做?
const renderFieldOne = ({ input, label, type, meta: { touched, error, warning } }) => (
<div>
<div className ="group">
<input className="text"
{...input}
type={type}/>
<label>{label}</label>
<span className="highlight"></span>
<span className="bar"></span>
{touched && ((error && <span>{error}</span>) || (warning && <span>{warning}</span>))}
</div>
</div>
)
答案 0 :(得分:0)
您需要为每个需要调用的函数单独传递每个道具
<renderFieldOne
input={renderFieldOneInputValue}
label={renderFieldOneLabelValue}
type={renderFieldOneTypeValue}
meta={touched}
/>
然后在renderFieldOne组件中可以执行
const renderFieldOne = ({input, label, type }) => {...}
通过解构,它将匹配的属性名称/值分配给传入的变量,将其用作引用https://amido.com/blog/using-es6-destructuring-in-your-react-components/。名称只需与属性匹配
或只是做
const renderFieldOne = (props) => {...}
and in each place call props.input or whatever prop you are trying to access.