我在react js中使用redux表单。出于可重复使用的目的,我将功能组件放在如下所示的单独文件中。
RenderFields.js
import React from "react";
function renderFields({
input,
label,
type,
meta: { touched, error, warning }
}) {
return (
<div>
<div className="control">
<label className="field">{label}</label>
..........................
</div>
</div>
</div>
);
}
export default renderFields;
我只想在终端类组件中使用它。
Terminal.js
import React, { Component } from "react";
import renderFields from "../../renderComponents/RenderFields";
class Terminal extends Component {
constructor(props) {
super(props);
this.state = {
name: "",
uid: "",
status: null
};
}
......................
render() {
return (
<div className="Terminal">
<div className="card">
<div id="Terminalform">
<form
class="container-fluid terminalform "
onChange={this.handleSubmit}
>
<div class="content">
{/*Terminal Name */}
<FormGroup controlId="name" bsSize="large">
<ControlLabel>TERMINAL NAME</ControlLabel>
<Field
style={{ width: "100%" }}
component={renderFields}
name="name"
type="text"
onChange={this.handleChange}
/>
</FormGroup>
</div>
</form>
</div>
</div>
</div>
);
}
}
Terminal = reduxForm({
form: "terminalform"
})(Terminal);
运行这些文件时,出现如下错误。
有人可以帮助我解决此错误吗?
更新
我将RenderField函数包装到如下组件中
import React, { Component } from "react";
class RenderFields extends Component {
render() {
const { label, input, type, touched, error, warning } = this.props;
return (
<div>
<div className="control">
<label className="field">{label}</label>
<input
className="input"
style={{ width: "100%" }}
{...input}
placeholder={label}
type={type}
/>
<br />
<div style={{ color: "red" }}>
{touched &&
((error && <span>{error}</span>) ||
(warning && <span>{warning}</span>))}
</div>
</div>
</div>
);
}
}
export default RenderFields;
但是我仍然遇到相同的错误。