最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error with React-TailwindCSS Datepicker in React 18: Cannot read properties of undefined - Stack Overflow

programmeradmin2浏览0评论

I am trying to add the react-tailwindcss-datepicker to my project by following the documentation here:

/install

However, I'm encountering the following error:

react-jsx-runtime.development.js:348 Uncaught TypeError: Cannot read properties of undefined (reading 'A')

The above error occurred in the <Datepicker> component:

I added the following configuration to my tailwind.config.js:

tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    './index.html',
    './src/**/*.{js,jsx,ts,tsx}',
    './node_modules/react-tailwindcss-datepicker/dist/index.esm.js',
  ],
  theme: {
    extend: {},
  },
  plugins: [require('@tailwindcss/forms')],
};

I used the Datepicker component like this:

import { useState } from "react"; 
import Datepicker from "react-tailwindcss-datepicker";

const App = () => { 
    const [value, setValue] = useState({ 
        startDate: null, 
        endDate: null
    });

    return (
        <Datepicker 
            value={value} 
            onChange={newValue => setValue(newValue)}
        /> 
    );
};

export default App;

I installed the required packages using the following commands:

npm install dayjs
npm add [email protected]

Even after following the documentation, I am facing the error mentioned above. It seems related to undefined properties when rendering the component.

Can anyone help me understand what the issue is or suggest a solution?

I am trying to add the react-tailwindcss-datepicker to my project by following the documentation here:

https://react-tailwindcss-datepicker.vercel.app/install

However, I'm encountering the following error:

react-jsx-runtime.development.js:348 Uncaught TypeError: Cannot read properties of undefined (reading 'A')

The above error occurred in the <Datepicker> component:

I added the following configuration to my tailwind.config.js:

tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
  content: [
    './index.html',
    './src/**/*.{js,jsx,ts,tsx}',
    './node_modules/react-tailwindcss-datepicker/dist/index.esm.js',
  ],
  theme: {
    extend: {},
  },
  plugins: [require('@tailwindcss/forms')],
};

I used the Datepicker component like this:

import { useState } from "react"; 
import Datepicker from "react-tailwindcss-datepicker";

const App = () => { 
    const [value, setValue] = useState({ 
        startDate: null, 
        endDate: null
    });

    return (
        <Datepicker 
            value={value} 
            onChange={newValue => setValue(newValue)}
        /> 
    );
};

export default App;

I installed the required packages using the following commands:

npm install dayjs
npm add [email protected]

Even after following the documentation, I am facing the error mentioned above. It seems related to undefined properties when rendering the component.

Can anyone help me understand what the issue is or suggest a solution?

Share Improve this question edited Mar 4 at 20:38 rozsazoltan 11.4k6 gold badges21 silver badges60 bronze badges asked Mar 4 at 19:50 D BinaraD Binara 712 silver badges8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Related: onesine/react-tailwindcss-datepicker issue #300

In theory, version 1.7.3 should also work. In this case, I can imagine that you might have accidentally installed version 2.0.0 at first, or possibly 1.7.4 (which has since been removed a few weeks ago). If so, delete your lock file and the node_modules folder, then reinstall version 1.7.3.

I'm going to release a major version, i.e. version 2.0.0, and unpublish version 1.7.4.


Source: onesite's comment from issue #300

If that doesn't help, and if you are using React 18, it is recommended to use version 1.7.2.

npm install [email protected]

Otherwise, to fix the issue, you need to migrate the entire project to React 19 and use the new react-tailwindcss-datepicker v2 version.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论