Thursday, December 26, 2024
Google search engine
HomeLanguagesHow to create Emoji Picker in ReactJS ?

How to create Emoji Picker in ReactJS ?

Emojis have become an essential part of modern communication, adding a touch of emotion and fun to our messages and applications. In this article, we will explore how to create an Emoji Picker using ReactJS, allowing users to easily select and insert emojis into their text inputs or text areas. 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 create our Spreadsheet we are going to use the emoji-picker-react package because it is powerful, lightweight, and fully customizable. After that, we will add an emoji picker on our homepage using the installed package.

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

npx create-react-app gfg

Module Installation: Install the emoji-picker-react package using the below command:

npm i emoji-picker-react

Project Structure: It will look like this.

Filename: App.js In this example, we are going to add the emoji picker on the homepage of our app using the package that we installed. For this, add the below content in the App.js file.

Javascript




import React, { useState } from 'react';
import Picker from 'emoji-picker-react';
 
export default function Emoji() {
    const [chosenEmoji, setChosenEmoji] = useState(null);
 
    const onEmojiClick = (event, emojiObject) => {
        setChosenEmoji(emojiObject);
    };
 
    return (
        <div>
            <h3>neveropen Emoji Picker</h3>
            {chosenEmoji ? (
                <span>Your Emoji: {chosenEmoji.emoji}</span>
            ) : (
                <span>No Emoji</span>
            )}
            <Picker onEmojiClick={onEmojiClick} />
        </div>
    );
};


Explanation: In the above example first, we are importing the Picker component from the emoji-picker-react package. After that, we are using our useState to add the initial data and update the emoji. Then we are adding our Emoji PIcker using the Picker component.

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

npm start

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