Search code examples
reactjsreact-datepicker

How to get the years 1990 to 2022 and possibly into the future?


I want to create a select and select box from 1990 to present. But it returns an error like: Uncaught TypeError: (0 , react_datepicker__WEBPACK_IMPORTED_MODULE_4__.range) is not a function

Mycode:

const years = range(1990, getYear(new Date()) + 1, 1);

What i need


Solution

  • The error means, compiler is unable to find a range function. Most likely in the the example it's referring to lodash range function. You can import it OR can create one yourself -

    function range (start, end) {
      return new Array(end - start).fill().map((d, i) => i + start);
    }
    
    console.log(range(5,10));