DEV Community

Netsai
Netsai

Posted on

React Emoji Picker

Sure! Here are some more details about the react-emoji-picker library:

react-emoji-picker is a lightweight and customizable emoji picker for React. It provides a simple and intuitive interface for users to select emojis, and it's easy to integrate into your React project.

The library provides a single EmojiPicker component that you can use to add an emoji picker to your project. The EmojiPicker component accepts several props to customize its appearance and behavior, including:

onEmojiSelect: A callback function that is called when an emoji is selected. The function receives the selected emoji's Unicode representation as a parameter.
rows: The number of rows of emojis to display in the picker. Default is 6.
perRow: The number of emojis to display per row. Default is 8.
emojiSize: The size of the emojis in pixels. Default is 24.
pickerStyle: An object containing CSS styles to apply to the picker container.
In addition, the library provides a getEmojiData function that you can use to get information about all the available emojis, including their Unicode representations, names, and images.

Overall, react-emoji-picker is a simple and effective solution for adding an emoji picker to your React project. It's easy to use and customize, and it provides all the basic features you need to allow your users to express themselves with emojis.

First, install the library using npm or yarn:

npm install react-emoji-picker
yarn add react-emoji-picker
Enter fullscreen mode Exit fullscreen mode

Import the EmojiPicker component from react-emoji-picker:

import React, { useState } from 'react';
import EmojiPicker from 'react-emoji-picker';
Enter fullscreen mode Exit fullscreen mode

Add the EmojiPicker component to your component's render method:

function EmojiPickerExample() {
  const [selectedEmoji, setSelectedEmoji] = useState(null);

  function handleEmojiSelect(emoji) {
    setSelectedEmoji(emoji);
  }

  return (
    <div>
      <h1>Selected Emoji: {selectedEmoji}</h1>
      <EmojiPicker onEmojiSelect={handleEmojiSelect} />
    </div>
  );
}

export default EmojiPickerExample;
Enter fullscreen mode Exit fullscreen mode

In this example, the EmojiPicker component is wrapped in a div, and the onEmojiSelect prop is set to a function that will be called when an emoji is selected. The handleEmojiSelect function updates the selectedEmoji state with the selected emoji's Unicode representation. Finally, the selected emoji is displayed in an h1 tag.

Customize the EmojiPicker by passing props to it. For example, you can set the size of the emojis, the number of columns, the style of the picker, and more:

<EmojiPicker
  onEmojiSelect={handleEmojiSelect}
  rows={4}
  perRow={8}
  emojiSize={32}
  pickerStyle={{ position: 'absolute', bottom: '20px', right: '20px' }}
/>
Enter fullscreen mode Exit fullscreen mode

In this example, the rows prop sets the number of rows to 4, the perRow prop sets the number of columns to 8, the emojiSize prop sets the size of the emojis to 32 pixels, and the pickerStyle prop positions the picker at the bottom right corner of the screen.

Top comments (1)

Collapse
 
madzimai profile image
Netsai

Have a nice time ๐Ÿ™Œ