Art*_*Art 2 datepicker reactjs
我的 Meteor/React 应用程序中的 datepicker,我找不到设置/更新状态以从道具加载默认值的方法。
import DatePicker from "react-datepicker";
export default class AddDate extends React.Component {
constructor(props) {
super(props);
this.state = {
startDate: this.props.start.format('MM/DD/YYYY')
};
}
handleStartDate(date) {
this.setState({
startDate: date
});
}
render() {
return (
<DatePicker
selected={this.state.startDate}
onChange={this.handleStartDate.bind(this)}
className="form-control"
id="startDate"
todayButton={"Get Today's Date"} />
);
}
}
AddDate.propTypes = {
start: PropTypes.object.isRequired,
};
Run Code Online (Sandbox Code Playgroud)
最初,道具来自 Fullcalendar“选择”事件,它提供(开始,结束)。
我得到的错误是:“未捕获的类型错误:t.date.clone 不是函数”
该startDate道具应该是一个(时刻)的对象,而不是字符串。没必要format()吧。
import moment from "moment";
// ...
this.state = {
startDate: moment(this.props.start),
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8833 次 |
| 最近记录: |