Sling Academy
Home/Next.js/How to use Ant Design in a Next.js project

How to use Ant Design in a Next.js project

Last updated: January 08, 2023

Next.js is a React framework that is used to build fast, high-performance, hybrid static and server-side rendering web applications.

Ant Design is a UI library that provides a lot of pre-made React components like Button, DatePicker, DropDown, Drawer, etc., which can help you create beautiful and enterprise-class products.

In this article, you will learn how to use Ant Design in a Next.js project.

Basic Setup

1. Open your terminal window and navigate to the place you want your Next.js project to locate, then run the following command:

npx create-next-app example

The name is totally up to you.

2. Navigate to the project root folder:

cd example

3. Install the Ant Design core and its icon set by executing the command below:

npm install antd @ant-design/icons --save

4. Now you can use the components and icons you like by importing them from antd and @ant-design/icons, respectively, like this:

import { Button, Space, DatePicker, Card } from 'antd';
import { SearchOutlined } from '@ant-design/icons';

Note that you can find all available icons provided by Ant Design at /node_modules/@ant-design/icons/lib/icons/index.d.ts.

Example

Replace the default code in your pages/index.js with the following:

import { Button, Space, DatePicker, Card } from 'antd';
import { SearchOutlined } from '@ant-design/icons';

export default function Home() {
  const onChange = () => {};
  return (
    <div style={{ padding: 100 }}>
      <Space direction="vertical">
        <Button type="primary">Primary Button</Button>
        <Button type="ghost">Ghost Button</Button>
        <DatePicker onChange={onChange} />
        <SearchOutlined style={{fontSize: 60, color: 'green'}} />
        <Card>
          <p>Card content</p>
        </Card>
      </Space>
    </div>
  );
}

Get your app up and running by executing the following command:

npm run dev

Go to http://localhost:3000 on your web browser and check the result:

That’s it. Happy coding!

Next Article: How to Correctly Use Bootstrap 5 in Next.js

Previous Article: How to use Font Awesome with Next.js

Series: Working with CSS in Next.js

Next.js

Related Articles

You May Also Like

  • Solving Next.js Image Component Error with CSS Classes
  • How to Use MUI (Material UI) in Next.js 14
  • Fixing Data Update Issues in Next.js Production
  • Fixing Next.js Undefined ENV Variables in Production Build
  • Solving Next.js SyntaxError: Unexpected token ‘export’
  • Next.js Error: Found Page Without a React Component as Default Export – How to Fix
  • Fixing Next.js Error: Blank Page on Production Build
  • Fixing Next.js Error when Importing SVGs: A Step-by-Step Guide
  • Next.js Issue: useEffect Hook Running Twice in Client
  • Fixing ‘self’ is not defined error in Next.js when importing client-side libraries
  • How to Dockerize a Next.js App for Production
  • How to set up Next.js with Docker Composer and Nginx
  • Solving Next.js CORS Issues: A Comprehensive Guide
  • Fixing Next.js Hydration Mismatch Error in Simple Ways
  • Next.js Error: Cannot use import statement outside a module
  • Next.js: How to Access Files in the Public Folder
  • Fixing Next.js Import CSS Error: A Simple Guide
  • Fixing LocalStorage Not Defined Error in Next.js
  • Fixing Next.js Error: No HTTP Methods Exported