Logo

dev-resources.site

for different kinds of informations.

How to Install Shadcn with Next.js 14: A Step-by-Step Guide

Published at
8/18/2024
Categories
nextjs
shadcn
frontend
react
Author
swhabitation
Categories
4 categories in total
nextjs
open
shadcn
open
frontend
open
react
open
Author
12 person written this
swhabitation
open
How to Install Shadcn with Next.js 14: A Step-by-Step Guide

Fastness means using the best and most up-to-date tools and frameworks in the ever-fast-developing web development world at your fingers.

Next.js 14 stands as a robust and go-to powerhouse for building React apps—every developer's MUST-HAVE in their kit. But what if you could supercharge your Next.js project with a sleek, modern UI library like Shadcn? You're in luck!

Why Shadcn and Next.js 14?

But before we dive into the installation process, let's cover quickly why Shadcn and Next.js 14 make a perfect pair.

Next.js 14 provides a strong base for server-side rendering, static site generation, and client-side React applications. Then there is the power of the UI component library called Shadcn.

Similarly, you will be able to create a high performance and beautiful UI-based application, and at the same time, enable scalability.

Prerequisites

Before you begin, be sure you have the following.

  • Background knowledge of React and Next.js.
  • You are expected to have Node.js installed in your system, preferably the latest version.
  • Install a package manager like npm or yarn.
  • Code editor like Visual Studio Code.

Step 1: Setting Up a New Next.js 14 Project

First, we are going to create a new Next.js 14 project. Open your terminal and run this command:

npx create-next-app@latest my-shadcn-app
cd my-shadcn-app
Enter fullscreen mode Exit fullscreen mode

This command will scaffold a new Next.js project for you. After the setup is complete, navigate into your project directory and start the development server:

npm run dev
Enter fullscreen mode Exit fullscreen mode

You should now be seeing your new Next.js app running locally at http://localhost:3000. You have just created a brand-new Next.js 14 project.

Step 2: Installing Shadcn

Now that you have Next.js 14 up and running, it's time to install Shadcn. You can do this quite easily by using npm or yarn. Run the following in the root of your project:

Using npm:

npm install shadcn
Enter fullscreen mode Exit fullscreen mode

Using yarn:

yarn add shadcn
Enter fullscreen mode Exit fullscreen mode

There you go! Shadcn is installed in your project; however, this isn't the end. Envision integrating it with your Next.js App.

Step 3: Integrating Shadcn with Next.js 14

First, to use Shadcn, you need to import its elements and into the Next.js pages. Modify pages/index.js to add a Shadcn button:

import { Button } from 'shadcn';

export default function HomePage() {
  return (
    <div>
      <h1>Welcome to My Shadcn App</h1>
      <Button>Click Me</Button>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Save the file, flip over to the browser, and refresh that page. Voilà! A brand new, shiny button from Shadcn!

Step 4: Customizing Shadcn Components

Shadcn components are designed to be easily modified, so you can make your application exactly the way you want it to be. Now let's make a few adjustments to the button we've just added using Tailwind CSS:

<Button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">

Custom Styled Button

</Button>
Enter fullscreen mode Exit fullscreen mode

You have only taken a few classes, yet this bland default button is now a nicely styled component for any design.

Step 5: Deploying Your Next.js 14 Project

Once you have a Next.js 14 app satisfied and Shadcn integration, it's time to deploy! Next.js makes that pretty easy. Even more so with Vercel. Here's how to do it:

Install the Vercel CLI (if you haven’t already):

npm install -g vercel
Enter fullscreen mode Exit fullscreen mode

Deploy your project:

vercel --prod
Enter fullscreen mode Exit fullscreen mode

Just follow the on-screen instructions, and in just a few moments, your app will be live on the web!

Conclusion

In this post, we ran through steps to set up a Next.js 14 project, installed Shadcn, integrated it into your app, and finally deployed your project. You now have the backbone that joins the power of Next.js 14 with the flexibility of Shadcn to build breathtakingly amazing ultra-high-performance web apps.

Remember, this is just the beginning! Research more Shadcn components, try more Next.js features, and take your projects to the next level.

shadcn Article's
30 articles in total
Favicon
Made FOSS for simplifying NextJS dev with OAuth And Postgres
Favicon
.gitkeep file in Shadcn/ui source code
Favicon
Introducing the Zod Schema Designer: A Visual Tool for Creating and Editing Zod Schemas
Favicon
Handling Local Storage for Toaster Notifications
Favicon
I created a visually pleasing HTML color viewer
Favicon
AISEKA Color Tool Website
Favicon
Color Palette is served with ShadCn Theme Editor
Favicon
Create React project with Vite and set up Tailwind, shadcn/ui
Favicon
Why Developers Love the Shadcn Sidebar Component
Favicon
A comparison of metadata configurations between Lobechat and Shadcn/ui
Favicon
Forms in seconds with ShardCn forms
Favicon
What is the Difference Between Radix UI and ShadCN?
Favicon
How Shadcn CLI uses error constants to improve code readability
Favicon
Exploring the ShadCN UI Library: A Comprehensive Guide
Favicon
10 Essential Shadcn Components Every Developer Should Know About
Favicon
The beginning of my open source journey
Favicon
Install ShadCN and Tailwind in Vite React Project
Favicon
How to add shadcn to existing project
Favicon
How to Use Shadcn UI with a React Project
Favicon
How to Install Shadcn with Next.js 14: A Step-by-Step Guide
Favicon
Shadcn Date Picker with custom implementation
Favicon
How to Fix Shadcn UI Adding Wrong Folder for Components
Favicon
Material UI vs Shadcn
Favicon
Building UIs with Franken UI, a Shadcn alternative
Favicon
Implement ShadCn form with Validation
Favicon
Top 5 Coolest shadcn/ui Extensions
Favicon
Shadcn UI: Must-Have Tools & Resources
Favicon
shadcn-ui/ui codebase analysis: examples route explained.
Favicon
Two ways I discovered to pass dynamic parameters in (arrow and non-arrow) function.
Favicon
Creating a User Nav bar in Next.js 14 using Shadcn UI and Tailwind CSS

Featured ones: