How do I import Ant Design React UI library and css?

Viewed 8572

I am very new to UI libraries and css in React. I'm using a data picker from Ant Design: https://ant.design/docs/react/introduce.

They provide CodePen examples and in the css tab you can see this:

@import 'antd/dist/antd.css';

However, when I add this to my css stylesheet which I import in to the component using `import './Component.css'; I get the error "Module not found: Can't resolve './antd/dist/antd.css'" in the components folder.

I have installed the npm package but can't get the css to work.

What am I doing wrong?

Many thanks.

1 Answers

Make sure antd is installed correctly and it's visible in your package.json it should be there

"antd": "3.19.2" assuming you ran npm i antd

as well as importing it in your component with

import { DatePicker } from 'antd';

Then import the style manually in your component

import 'antd/dist/antd.css';

Related