Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to add Color Picker in NextJS ?

  • Last Updated : 14 Dec, 2021

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 - GeeksforGeeks</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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!