Friday, October 10, 2025
HomeLanguagesJavascriptHow to Drawing Canvas in React.js ?

How to Drawing Canvas in React.js ?

In this article, we are going to learn how we can add drawing canvas in ReactJs. React is a free and open-source front-end JavaScript library for building user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies.

Approach: To add our canvas we are going to use the react-canvas-paint package. The react-canvas-paint package helps us to integrate the drawing canvas in our app. So first, we will install the react-canvas-paint package and then we will add a canvas on our homepage.

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

npx create-react-app gfg

Install the required package: Now we will install the react-canvas-paint package using the below command:

npm i react-canvas-paint

Project Structure: It will look like this.

Adding the Drawing Canvas: After installing the package we can easily add a canvas on any page in our app. For this example, we are going to add a canvas to our homepage.

Add the below content in the App.js file:

Javascript




import React from "react";
import ReactCanvasPaint from 'react-canvas-paint'
import 'react-canvas-paint/dist/index.css'
 
export default function DrawingCanvasGfg() {
    return (
        <div>
            <h1>ReactJs Drawing Canvas - neveropen</h1>
            <ReactCanvasPaint />
        </div>
    );
};


Explanation: In the above example first, we are importing the ReactCanvasPaint component and after that, we are using the installed component in a new function to add our drawing canvas.

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

npm start

Output:

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS