超出最大调用堆栈大小?

Maximum call stack size exceeded?

我在我的项目中添加日期范围选择器,当我在一个单独的项目中 运行 日期范围选择器时它工作正常但是当我尝试将它与我的项目集成时我用相同的代码得到了这个错误“未捕获的 RangeError:超出最大调用堆栈大小” 这是我的日期范围选择器代码 这是我的 Date.js 文件


import React, { Component } from 'react';

import  {DateRangePicker}  from 'react-date-range';
import { addDays } from 'date-fns';

import moment from 'moment'
import 'react-date-range/dist/styles.css'; // main style file
import 'react-date-range/dist/theme/default.css'; // theme css file

class Date extends Component {
  handleSelect(ranges){
    console.log(ranges);
 
  }
  constructor(props) {
    super(props);
    this.state = {
      selectionRange: {
        startDate: new Date(),
        endDate: addDays(new Date(), 7),
       
        key: "selection"
      }
    }
  }
  

  handleDateSelect = (item) => {
    this.setState({
      ...item
    });
  }

  render()
  {
 
    return (
   
 
      <DateRangePicker
     
      onChange={(item) => this.setState({selectionRange: item.selection})}
   

      showSelectionPreview={true}
      moveRangeOnFirstSelection={false}
      months={2}
     
      ranges={[this.state.selectionRange]}
     
      direction="horizontal"
    />
    );
  }
}

export default Date

谁能帮我解决这个问题?我在我的控制台中收到此错误

您 class 被命名为 Date,因此当您调用 new Date() 时,您正在调用 class 的构造函数。这会递归发生并导致堆栈溢出。

尝试将您的 class 重命名为其他名称(例如 DatePicker)。