Skip to content

Compat API

A drop-in replacement for react-emoji-render. Pass adapted emoji data directly via options — no provider needed. Works with both @emoji-mart/data and emojibase-data.

import emojiMartData from '@emoji-mart/data';
import { fromEmojiMart } from 'react-emoji-text/adapters/emoji-mart';
import Emoji from 'react-emoji-text/compat';
const data = fromEmojiMart(emojiMartData);
<Emoji text="hello :wave:" options={{ data }} />
<Emoji text=":wave:" onlyEmojiClassName="jumbo" options={{ data }} />
<Emoji
text=":wave:"
svg
options={{ data, imageUrlTemplate: '/emoji/{set}/{unified}.png' }}
/>
hello 👋 world ❤️
PropTypeDefaultDescription
textstringrequiredSource text
onlyEmojiClassNamestringClass when content is only emojis
svgbooleanWhen true, uses the "apple" set
optionsCompatOptionsrequiredTokenize and render options
refRef<HTMLSpanElement>Forwarded ref

All additional HTML attributes are forwarded to the wrapper <span>.

Returns an array of strings and React elements for manual rendering:

import emojiMartData from '@emoji-mart/data';
import { fromEmojiMart } from 'react-emoji-text/adapters/emoji-mart';
import { toArray } from 'react-emoji-text/compat';
const data = fromEmojiMart(emojiMartData);
const elements = toArray('hello :wave:', { data });
// ['hello ', <span title="wave">👋</span>]

Accepts the same CompatOptions as the Emoji component’s options prop.

Create a thin wrapper to pre-configure the data source once, then use it everywhere without repeating the adapter setup:

emoji.tsx
import emojiMartData from '@emoji-mart/data';
import { fromEmojiMart } from 'react-emoji-text/adapters/emoji-mart';
import BaseEmoji, { toArray as baseToArray } from 'react-emoji-text/compat';
import type { EmojiProps } from 'react-emoji-text/compat';
const data = fromEmojiMart(emojiMartData);
export default function Emoji(props: Omit<EmojiProps, 'options'>) {
return <BaseEmoji {...props} options={{ data }} />;
}
export function toArray(text: string) {
return baseToArray(text, { data });
}

Then import from your wrapper instead:

import Emoji, { toArray } from './emoji';
<Emoji text="hello :wave:" />;
toArray('hello :wave:');
  • Data source: Uses adapter functions (fromEmojiMart or fromEmojibase) instead of the legacy dataset. More emojis, more accurate shortcodes.
  • Data source agnostic: Works with both @emoji-mart/data and emojibase-data via their respective adapters.
  • Skin tones: Supported via defaultSkin option (not available in the original).
  • ASCII matching: Uses boundary-aware matching to avoid false positives in URLs and code.
  • No EmojiProvider required: Data is passed directly via options.data — no React context provider needed.
  • svg prop: Accepted for migration compatibility. It selects an image set, but callers still provide assets through options.getImageUrl, options.imageUrlTemplate, or options.sprite. This package does not host or bundle emoji images.