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

Plural does not work with useState #1125

Closed
MOTORIST opened this issue May 25, 2020 · 1 comment
Closed

Plural does not work with useState #1125

MOTORIST opened this issue May 25, 2020 · 1 comment

Comments

@MOTORIST
Copy link

MOTORIST commented May 25, 2020

#248 🐛 Bug Report

When "count" changes, the translation does not change.

const Com = ()  => {
  const [hintValue, setHintValue] = useState(null);
  const { t } = useTranslation(null);

  const handleOnChange = (e) => {
    setHintValue(t('hint', {count: e.target.value}));
    console.log(t('hint', {count: e.target.value}));
  }

  return (
   <div>
     <div className="FormGroup">
      <input className="Input" type="number" onChange={handleOnChange} />
      <div className="FormGroup-Hint">{hintValue}</div>
    </div>

    <hr/>
      <div>1: {t('hint', {count: 1})}</div>
      <div>5: {t('hint', {count: 5})}</div>
   </div>
  );
}

To Reproduce

stackblitz.com

Your Environment

  • i18next version: 19.4.4
  • react-i18next version: 11.5.0
@MOTORIST
Copy link
Author

My mistake (

setHintValue(t('hint', {count: +e.target.value}));

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

No branches or pull requests

1 participant