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

React 18 - Trans component interpolation issue #1490

Closed
enoh-barbu opened this issue Apr 27, 2022 · 2 comments · Fixed by #1492
Closed

React 18 - Trans component interpolation issue #1490

enoh-barbu opened this issue Apr 27, 2022 · 2 comments · Fixed by #1492
Assignees

Comments

@enoh-barbu
Copy link

I've just upgraded to react v18 but I get an error while doing interpolation using Trans component

<Trans i18nKey="pageNrOfAll" pageNr={pageNr} pagesCount={pagesCount}>
    Page
    <strong className="spacing">{{ pageNr }}</strong>
    of
    <strong className="spacing">{{ pagesCount }}</strong>
 </Trans>

image

Type '{ pageNr: number; }' is not assignable to type 'ReactNode'.
  Object literal may only specify known properties, and 'pageNr' does not exist in type 'ReactElement<any, string | JSXElementConstructor<any>> | ReactFragment | ReactPortal'.ts(2322)
index.d.ts(1375, 9): The expected type comes from property 'children' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'

If I keep only one pair of brackets { pageNr } I get the following error

react-i18next:: Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.

https://codesandbox.io/s/brave-bohr-obwf63

I've just posted the same question on stackoverflow

@adrai
Copy link
Member

adrai commented Apr 27, 2022

probably duplicate of #1483

@adrai
Copy link
Member

adrai commented May 5, 2022

v11.16.8 offers allowObjectInHTMLChildren option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants