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

Type error for tag interpolation when using useTranslate hook #3337

Closed
Yureien opened this issue May 9, 2024 · 1 comment
Closed

Type error for tag interpolation when using useTranslate hook #3337

Yureien opened this issue May 9, 2024 · 1 comment

Comments

@Yureien
Copy link

Yureien commented May 9, 2024

This is what is stated in the documentation, and works successfully:

const Component = () => {
  return (
    <div>
      <T
        keyName="translation_key"
        params={{ i: <i /> }}
        defaultValue="This is <i>formatted</i>"
      />
    </div>
  );
};

However, this gives a type error with the equivalent useTranslate hook:

const { t } = useTranslate();

const result = t("translation_key", "This is <i>formatted</i>", { i: <i /> });

It seems that the DefaultParamType does not accept JSX.Element types:

export type DefaultParamType = string | number | bigint | Date;
@stepan662
Copy link
Collaborator

Hey, this is intentional, as the t function is supposed to always return simple string. In contrast, T component always returns JSX.Element, so the intention is to express different usecases for these two primitives.

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

3 participants