Tuesday, January 14, 2025
Google search engine
HomeLanguagesHow to add Color Picker in NextJS ?

How to add Color Picker in NextJS ?

In this article, we are going to learn how we can add a color picker in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. 

Approach: To add our color picker we are going to use the react-color-palette package. The react-color-palette package helps us to integrate different types of color pickers. So first, we will install the react-color-palette package, and then we will add a color picker on our homepage.

Create NextJS Application: You can create a new NextJs project using the below command:

npx create-next-app gfg

 

Install the required package: Now we will install the react-color-palette package using the below command:

npm i react-color-palette

Project Structure: It will look like this.

Adding the Color Picker: After installing the package we can easily add color picker on any page in our app. For this example, we are going to add color picker to our homepage.

index.js




import React from 'react';
import { ColorPicker, useColor } from "react-color-palette";
import "react-color-palette/lib/css/styles.css";
  
export default function SkeletonLoading(){
  const [color, setColor] = useColor("hex", "#121212");
  return (
    <div>
      <h2>NextJs Color Picker - neveropen</h2>
      <ColorPicker width={456} height={228} color={color} 
                   onChange={setColor} hideHSV dark />
    </div>
  )
}


Explanation: In the above example first, we are importing the Color Picker component and after that, we are using useColor hook to store the value of the selected color. Then we are adding our color picker using the imported component.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments