Skip to content

Commit

Permalink
Emoji [nfc]: Use useSelector instead of connect.
Browse files Browse the repository at this point in the history
An instance of zulip#4837.
  • Loading branch information
chrisbobbe committed Aug 27, 2021
1 parent 99a882f commit c50515e
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/emoji/Emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from 'react';
import { Image } from 'react-native';
import { createIconSet } from 'react-native-vector-icons';

import type { ImageEmojiType, Dispatch, EmojiType } from '../types';
import type { EmojiType } from '../types';
import { createStyleSheet } from '../styles';
import { connect } from '../react-redux';
import { useSelector } from '../react-redux';
import { getAllImageEmojiByCode } from './emojiSelectors';
import { codeToEmojiMap } from './data';

Expand All @@ -14,30 +14,22 @@ import { codeToEmojiMap } from './data';
*/
const UnicodeEmoji = createIconSet(codeToEmojiMap);

type SelectorProps = {|
imageEmoji: ImageEmojiType | void,
|};

type Props = $ReadOnly<{|
type: EmojiType,
code: string,

dispatch: Dispatch,
...SelectorProps,
|}>;

const componentStyles = createStyleSheet({
image: { width: 20, height: 20 },
});

function Emoji(props: Props) {
const { code, imageEmoji } = props;
export default function Emoji(props: Props) {
const { code } = props;
const imageEmoji = useSelector(state =>
props.type === 'image' ? getAllImageEmojiByCode(state)[props.code] : undefined,
);
if (imageEmoji) {
return <Image style={componentStyles.image} source={{ uri: imageEmoji.source_url }} />;
}
return <UnicodeEmoji name={code} size={20} />;
}

export default connect<SelectorProps, _, _>((state, props) => ({
imageEmoji: props.type === 'image' ? getAllImageEmojiByCode(state)[props.code] : undefined,
}))(Emoji);

0 comments on commit c50515e

Please sign in to comment.