在一个组件而不是另一个组件中从 date-fns 导入函数时遇到问题?

Having trouble importing a function from date-fns in one component but not another?

我正在尝试将此函数从 date-fns 库导入我的组件之一,如下所示:

import { eachMonthOfInterval } from "date-fns";

我正在组件中这样测试它:

  let result = eachMonthOfInterval({
      start: props.state.startDate ? new Date(props.state.startDate) : '', 
      end: props.state.endDate ? new Date(props.state.endDate) : ''
    })

  console.log(result)

不幸的是,我一直收到 TypeError: Object(...) is not a function

奇怪的是,我可以在另一个组件中使用 date-fns 中的 format(),这样导入时就好了:

import {format} from "date-fns";

所以...这是一个错误还是我在这里做错了什么?

编辑:这是 link 文档 https://date-fns.org/v2.14.0/docs/eachMonthOfInterval

你能试试这个吗。 首先,在你的终端中输入这个(确保终端在项目文件夹中):
npm install date-fns --save

    import React, { Component } from 'react'
import { eachMonthOfInterval } from 'date-fns'

class TimeInterval extends Component {
   constructor(props) {
      super(props)

   }

   render() {
      var result = eachMonthOfInterval({
         start: new Date(2014, 1, 6),
         end: new Date(2014, 7, 10)
       })
       console.log(result);
      return (
         <div>
            <h1 id='title'>Interval</h1>
            <table id='students'>
               <tbody>

               </tbody>
            </table>
         </div>
      )
   }
}

export default TimeInterval;