reactjs - 为什么日期范围选择器反应日期给出错误?
问题描述
元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。
import React from 'react'
import { connect } from 'react-redux';
import { DateRangepicker } from 'react-dates';
import {setTextFilter, sortByAmount, sortByDate, setStartDate,setEndDate} from '../actions/filters';
class ExpenseListFilters extends React.Component{
state={
calenderFocused:null
};
onDatesChange=({startDate,endDate})=>{
this.props.dispatch(setStartDate(startDate));
this.props.dispatch(setEndDate(endDate));
}
onFocusChange=(calenderFocused)=>{
this.setState(()=>({calendarFocused}));
}
render(){
return(
<div>
<input type="text"
value={this.props.filters.text}
onChange={(e)=>{
this.props.dispatch(setTextFilter(e.target.value));
}}/>
<select
value={ this.props.filters.sortBy }
onChange={(e)=>{
if(e.target.value === 'date'){
this.props.dispatch(sortByDate());
}else if(e.target.value === 'amount'){
this.props.dispatch(sortByAmount());
}
}}>
<option value="date">Date</option>
<option value="amount">Amount</option>
</select>
<DateRangepicker
startDate={this.props.filters.startDate}
endDate={this.props.filters.endDate}
onDatesChange={this.onDatesChange}
focusedInput={this.state.calenderFocused}
onFocusChange={this.onFocusChange}
/>
</div>
)
}
}
const mapStateToProps = (state) =>{
return{
filters:state.filters
}
}
export default connect(mapStateToProps)(ExpenseListFilters);`
解决方案
我相信您看到的问题是因为您的导入不正确。您需要导入DateRangePicker
而不是DateRangepicker
从“反应日期”导入 { DateRangePicker };
您可以在react-dates中查看更多详细信息。
推荐阅读
- python - matplotlib 在同一 x 轴上同时绘制折线图和条形图
- html - 在另一个 div 上显示 div 边框
- python - Python。sklearn.compose.ColumnTransformer 在他以前的位置不适合新列
- php - Laravel Passport 注销测试在应该被拒绝时返回 200
- angular - Angular 8:使用 formControlName 和 ControlValueAccessor 的 Mat-Select 下拉列表
- javascript - 选项卡和可折叠在同一页面上
- php - 图像自动尺寸需要
- c# - 多维数组必须是同一类型吗?
- python-3.x - 选择带有关键字的页面并抓取它
- swift - 使用 Where 语句从 Firebase 计算 Swift 中的记录