0
我对道具和功能组件有一个看似微不足道的问题。基本上,我有一个容器组件,它在状态改变时呈现模态组件,这是由用户点击一个按钮触发的。模态是一个无状态的功能组件,它包含一些需要连接到容器组件内部功能的输入域。反应:将道具传递给功能组件
我的问题:如何在用户与无状态Modal组件内的表单字段进行交互时使用居于父组件内部的功能来更改状态?我错误地传递道具吗?提前致谢。
集装箱
export default class LookupForm extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false
};
}
render() {
let close =() => this.setState({ showModal: false });
return (
... // other JSX syntax
<CreateProfile fields={this.props} show={this.state.showModal} onHide={close} />
);
}
firstNameChange(e) {
Actions.firstNameChange(e.target.value);
}
};
功能(模态)组分
const CreateProfile = ({ fields }) => {
console.log(fields);
return (
... // other JSX syntax
<Modal.Body>
<Panel>
<div className="entry-form">
<FormGroup>
<ControlLabel>First Name</ControlLabel>
<FormControl type="text"
onChange={fields.firstNameChange} placeholder="Jane"
/>
</FormGroup>
);
};
实施例:说我想调用this.firstNameChange
从模态分量内。我猜想把道具传递给功能组件的“解构”语法让我有点困惑。即:
const SomeComponent = ({ someProps }) = > { // ... };