-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
This JSX tag's 'children' prop expects a single child of type 'ReactI18NextChild | Iterable<ReactI18NextChild>' when using allowObjectInHTMLChildren
#1543
This JSX tag's 'children' prop expects a single child of type 'ReactI18NextChild | Iterable<ReactI18NextChild>' when using allowObjectInHTMLChildren
#1543
Comments
Hi @pedrodurek, any update on this? |
We're also having this problem unfortunately. |
same problem also with React 17 and react-i18next (v11.18.3) |
This is probably because the type definition is I think (could be wrong) that I also changed from |
I'm having a similar problem with PropTypes.InferProps. If I use PropTypes.node for my children prop, and use {children} in a simple div, I get this error: Type 'ReactNodeLike' is not assignable to type 'ReactI18NextChild | Iterable'. |
Same problem after bumping React to v18 |
Same |
Same issue here |
same here |
same issue here |
same issue if you have something like Type 'ReactNode' is not assignable to type |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Same issue here |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Same issue |
This is a big issue relative to typingm due to redefining children of react module. This JSX tag's 'children' prop expects a single child of type 'ReactI18NextChild | Iterable<ReactI18NextChild>', but multiple children were provided.
but multiple children were provided. |
Is that really the solution to just ignore the growing number of Typescript Users? |
@rene-stesl idk...but this module is far from ignoring typescript users. Just go through the changelog https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md and check how many releases are just related to work for typescript users. @pedrodurek puts a lot of his own (free) time into improving the typings and does an awesome job for the community. |
Thanks for backing me up @jamuhl, I appreciate it! @rene-stesl, the types here work perfectly, sometimes it's just hard to please everyone, but I'm doing my best here to address the issues whenever I have free time. |
@jamuhl, @pedrodurek I know that it is not easy to sacrifice your free time for such a project and only get criticism. This is definitely not my intention. But IMHO this ticket gets ignored since it was opened on Aug 15. I personally don't think the Types work perfectly in this case because if you just add react-i18next as dependency to an existing project it is possible that the build fails! And I personally think that just adding a dependency to a project shouldn't be able to do that! If someone can explain why the React Types were overwritten, it might be easier to find a solution. |
I guess (not a typescript user):
in react-i18next we decided long before that objects are a good way to pass in interpolation values and keeping i18next translation syntax So the solution is either to extend the types or not using objects inside react-elements. (Like said - i don't use typescript - so I just believe that this was the reason) |
@adrai in my case I'm not using any translations in components, just installed |
I can't see any error in the codesandbox example. |
@adrai according to this: https://www.i18next.com/overview/getting-started, my config seems legit :) "translation" <-- this is default ns ;) I changed the i18n confing so that it includes ns "default" and even added to useTranslation() hook, that it would use the "default" ns. The error is the same :) |
also in the getting started guide you see the translation namespace is defined in the language object: |
I see this error here is the fork version :) : https://codesandbox.io/s/i18next-type-error-mui-forked-ht2ctc |
ok, that was my bad. Sry. |
well, it works with older version of i18next / react-i18next :) |
@nicegamer7 can you have a look at this? |
This looks like an issue with MUI's types. I'll take a look when I get a chance. |
I found the issue in MUI's types. I'll make a PR there in a bit and post here when I do. |
You can install the version of |
The error is gone with the version you linked. Haven't been able to test everything thoroughly because there are a few other breaking changes in the version that's currently on @mui/material's master branch. Would it be too much to ask you to explain the fix? I see you typed the children prop of |
The argument in the Does that make sense? Hopefully my explanation is okay. |
Ah, so there was a mismatch in their own typings. That totally makes sense. Thanks for explaining! |
I also had the same problem as @serjiosilent Following @sourdenis advice, I downgraded to react-i18next v.12.2.2 and i18next v.22.5.1 and the problem went away. |
For those who will bump into the same issue, I'll share my experience regarding this problem. I got same error with following dependencied (listing only important ones):
Important here is a version of typescript. |
@nicegamer7 this resolved the issue for me, thanks! Hopefully your PR gets merged soon 🤞 |
It will get fixed? |
I just run into this. The fix was to wrap the props with React.PropsWithChildren |
I see this error @sourdenis Hi my friend, how to fix it |
In my case, using MUI Autocomplete with MUI TextField, here was the solution: Replace:
with:
|
I experiencing a similar to serjiosilent and sourdenis issue Why did only the installation of react-i18next cause these issues with MUI's TextFields? Thanks in advance. |
I also encountered the same problem, have you solved it? |
@zhouru1bin you can either downgrade the react-i18next or use the pr of mui above. Also, when I updated the typescript to v5 it solved the issue for me, but I am not sure why it appeared after all |
any reason not to use the following syntax?
Assuming MY_KEY = (instead of passing object as a child, just pass the value) |
That would not work with i18next-parser, which would write What seems to work for me is <Trans i18nKey='MY_KEY' values={{foo: 'bar'}}>
Hello <b>{'{'}{foo}{'}'}</b>
</Trans> Which does correctly write |
🐛 Bug Report
After upgrading to React v18 and Reacti18Next to v11.18, I had an issue with objects not being accepted inside the
Trans
component, something similar to this.The fix for that was to add the
allowObjectInHTMLChildren
property, which fix that issue, but it lead to another issue.Now, when I try to have the result of a
t
function along with some other strings inside ap
orspan
component, I get the errorTo Reproduce
Codesandbox - https://codesandbox.io/s/react-i18next-type-issue-uidhq7
Please check the error on
src/App.tsx:10
Proposed Solution
I tried playing around with the types in the library and it seems like changing
node_modules/react-i18next/ts4.1/index.d.ts:108
as follows will fix this.The problem, at least for me, seems to be with
Iterable<ReactI18NextChild>
not working as expected for multiple childrenThe text was updated successfully, but these errors were encountered: