Reactjs 使用反应日期http://airbnb.io/react-dates
我使用这个npm 我也是Reactjs 使用反应日期http://airbnb.io/react-dates,reactjs,npm,Reactjs,Npm,我使用这个npm 我也是 import { SingleDatePicker } from 'react-dates'; and in my render function I do <SingleDatePicker id="date" /> 从'react dates'导入{SingleDatePicker}; 在我的渲染函数中,我做到了 …就是这样,而且成功了。我试图将SingleDatePicker更改为第二个API,根据文档,它是DateRangePicker。我可以
import { SingleDatePicker } from 'react-dates';
and in my render function I do
<SingleDatePicker id="date" />
从'react dates'导入{SingleDatePicker};
在我的渲染函数中,我做到了
…就是这样,而且成功了。我试图将SingleDatePicker更改为第二个API,根据文档,它是DateRangePicker
。我可以看到它被渲染了,但当我单击它时,它什么也不做。我不知道出了什么问题,我的控制台中没有错误。列出了SingleDatePicker
组件所需的道具及其类型:
<SingleDatePicker
date={this.state.date} // momentPropTypes.momentObj or null
onDateChange={date => this.setState({ date })} // PropTypes.func.isRequired
focused={this.state.focused} // PropTypes.bool
onFocusChange={({ focused }) => this.setState({ focused })} // PropTypes.func.isRequired
/>
this.setState({date})//PropTypes.func.isRequired
聚焦={this.state.focused}//PropTypes.bool
onFocusChange={({focused})=>this.setState({focused}}//PropTypes.func.isRequired
/>
要处理用户交互,必须为onFocusChanged提供函数,为聚焦道具提供bool(如上所示)。使用上面的实现,您只需要向您的状态添加一个initalfocused
值
例如,state={……聚焦:false}
请注意,您需要使用包将日期对象生成到
date
prop。您确定从“react dates”导入了DateRangePicker吗?@squGEIm非常确定,因为正如我所说的,SingleDatePicker可以工作。