Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update selected_emojis.md #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Abdullah-Sheikh
Copy link

In the original documentation, there was an inconsistency in the use of the useState hook. The state variable was defined as currentlySelectedEmojis using const [currentlySelectedEmojis, setCurrentlySelectedEmojis] = useState([]), but in the rest of the code, it was incorrectly referenced as currentlySelected and setCurrentlySelected. This mismatch could lead to confusion and potential bugs, as the state variable and its updater function were not correctly named.

To resolve this issue, I corrected the naming of the state variable and its updater function. The correct code should consistently use currentlySelectedEmojis and setCurrentlySelectedEmojis throughout. This change ensures that the code is more readable and less prone to errors.

import EmojiPicker, { type EmojiType } from 'rn-emoji-keyboard';

const ExampleComponent = () => {
  const [currentlySelectedEmojis, setCurrentlySelectedEmojis] = useState([]);

  const handleOnEmojiSelected = (emoji: EmojiType) => {
    // Your on-select logic

    // Remove or add pressed emoji to the currently selected array
    if (emoji.alreadySelected) {
      setCurrentlySelectedEmojis((prev) => prev.filter((a) => a !== emoji.name));
    } else {
      setCurrentlySelectedEmojis((prev) => [...prev, emoji.name]);
    }
  };

  return (
    <EmojiPicker
      open={isOpen}
      onClose={handleOnClose}
      onEmojiSelected={handleOnEmojiSelected}
      selectedEmojis={currentlySelectedEmojis}
    />
  );
};

This update eliminates the naming inconsistency and aligns the state variable with its intended usage.

In the original documentation, there was an inconsistency in the use of the useState hook. The state variable was defined as currentlySelectedEmojis using const [currentlySelectedEmojis, setCurrentlySelectedEmojis] = useState([]), but in the rest of the code, it was incorrectly referenced as currentlySelected and setCurrentlySelected. This mismatch could lead to confusion and potential bugs, as the state variable and its updater function were not correctly named.

To resolve this issue, I corrected the naming of the state variable and its updater function. The correct code should consistently use currentlySelectedEmojis and setCurrentlySelectedEmojis throughout. This change ensures that the code is more readable and less prone to errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants