A
A
Andrey Okhotnikov2019-05-06 10:17:25
JavaScript
Andrey Okhotnikov, 2019-05-06 10:17:25

i18n translation utility?

In the project I created a utility to which I pass the text and it returns the translation The
question is - will a new function t be created with each call?

import { useTranslation } from 'react-i18next';

export default data => {
  const { t } = useTranslation();

  return t(data);
};

If you do this, will it fix the situation?
import { useTranslation } from 'react-i18next';
 const { t } = useTranslation();

export default data => {
  return t(data);
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-06
@tsepen

The question is - will a new function t be created with each call?

No, the useTranslation hook returns the same t function across redraws.
Get an error. Hooks don't work that way. They must be defined in the body of functional components.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question