【发布时间】:2019-10-15 07:17:38
【问题描述】:
尝试使用反应日期选择器从搜索中退出,然后检查可用日期。在将道具传递给 btn 时遇到了一些问题,因此我可以根据所选日期创建新页面。
一切都正确导入,我们可以在下面省略我的 Datapicker 组件和我需要使用 pop 的 Btnsearch 组件。
我尝试在组件的每个元素中传递道具,并将 btn 内置到组件中。我已经阅读了将道具传递到元素链中的更好方法。对于孩子们,所以我最后尝试这样做。似乎仍然无法捕捉到 Datepicked 甚至 console.log 它。也尝试构建警报。
class Datepicker extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ""
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({ value: event.target.value });
}
handleSubmit(event) {
alert("A name was submitted: " + this.state.value);
event.preventDefault();
}
state = {};
render() {
console.log(this.props.value);
return (
<>
<FormGroup>
<InputGroup className="input-group-alternative">
<InputGroupAddon addonType="prepend">
<InputGroupText
>
<i className="ni ni-calendar-grid-58" />
</InputGroupText>
</InputGroupAddon>
<ReactDatetime
value={this.state.value}
onChange={this.handleChange}
inputProps={{
placeholder: "Date Picker Here"
}}
timeFormat={false}
/>
</InputGroup>
</FormGroup>
<Btnsearch />
</>
);
}
}
export default Datepicker;
class Btnsearch extends React.Component {
render() {
return (
<button value={this.props.value} className="btn btn-success search-card-btn">Search</button>
);
}
};
export default Btnsearch;
我希望 console.log 并在单击按钮时提醒道具已更改以填充新页面。我得到未定义的道具
【问题讨论】:
标签: reactjs