npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-emoji-render

v2.0.1

Published

Render emoji's the way your users expect.

Downloads

66,734

Readme

npm version Tests

react-emoji-render

Normalize and render emoji's the way your users expect.

  • Supports unicode emoji characters
  • Supports emoticons such as :) :x :/
  • Supports slack-style emoji names such as :smile:
  • Choose between native, twemoji, emojione or custom image sets.
  • Add custom styles when text contains only emoji (to make it bigger, of course)

Live Demo on CodeSandbox

Installation

Install with your favorite package manager:

npm install react-emoji-render --save
yarn add react-emoji-render

Basic Usage

By default the component will normalize all of the different emoji notations to native unicode characters.

import Emoji from "react-emoji-render";

<Emoji text="This ❤️ sentence includes :+1: a variety of emoji types :)" />;

// or as a child
<Emoji>
  This ❤️ sentence includes :+1: a variety of emoji types :)
<Emoji/>;

Twemoji

Twemoji is an emoji set designed by Twitter, you can use the included Twemoji component to render emoji images in this style.

import { Twemoji } from 'react-emoji-render';

<Twemoji text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for svg images:
<Twemoji svg text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Emojione

Emojione is a great looking open source emoji set, you can use the included Emojione component to render emoji images in this style.

import { Emojione } from 'react-emoji-render';

<Emojione text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for svg images:
<Emojione svg text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

// or, for Emojione v4
<EmojioneV4 text="This ❤️ sentence includes :+1: a variety of emoji types :)" />
// note: only png supported -->
// https://github.com/emojione/emojione-assets/issues/2

// in v4 size prop can be set at 32, 64 (default) or 128
<EmojioneV4 size={32} text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Advanced Usage

Only Emoji

The className passed as the onlyEmojiClassName prop is added when the provided text contains only three or less emoji characters. This allows you to add custom styles in this scenario. For example:

<Emoji text=":+1:" onlyEmojiClassName="make-emojis-large" />

Array Output

If you want to do further processing on the output, for example parsing HTML then it may be useful to not have the normalized emojis be wrapped in a component.

import { toArray } from "react-emoji-render";

// content is an array of text and emoji components, you can now loop through this
// array and perform further processing. Avoid using `dangerouslySetInnerHTML`!
const content = toArray(
  "This ❤️ sentence includes :+1: a variety of emoji types :)"
);

Then, for example, you can parse all the text and emojis in a single string like the following:

const parseEmojis = value => {
  const emojisArray = toArray(value);

  // toArray outputs React elements for emojis and strings for other
  const newValue = emojisArray.reduce((previous, current) => {
    if (typeof current === "string") {
      return previous + current;
    }
    return previous + current.props.children;
  }, "");

  return newValue;
};

parseEmojis(":)hello"); // => "😃hello"

Custom Images

If you wish to use a custom emoji set / location then you can pass options into the props. One way to achive this is to create a wrapping component which provides your options and exposes a new component, something like:

import Emoji from "react-emoji-render";

function MyEmojiRenderer({ children, ...rest }) {
  const options = {
    baseUrl: "https://mycustom.cdn.com/emojis/",
    ext: "svg",
  };

  return <Emoji options={options} {...rest} />;
}

You can then use the new component:

<MyEmojiRenderer text="This ❤️ sentence includes :+1: a variety of emoji types :)" />

Contributing

Emojis and aliases

If our dataset is missing some emoji, please open an issue specifying which one is missing. The library has a package script (yarn update-aliases) that makes it easy to update with the latest emojis at any time. You can directly do it yourself and open a PR as well.

If you would like to add a new alias to an existing emoji, please find the emoji in our custom aliases file and add the alias to its array of aliases. If you have found a source of aliases that is being actively maintained and you would like to add it, please open an issue to discuss it.