question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow ReactNode to passed to values or InterpolationMap

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently, there’s no way to pass ReactNode to values or in the InterpolationMap for t. This seems like a really simple implementation for Trans, at least, looking at the code.

Describe the solution you’d like

const [t] = useTranslation();
return <div>{t('foo', {link: <a href="//tosomewhere.com">{t('to somewhere')}</a>})}</div>;

or

return (
  <Trans
    i18nKey="foo"
    values={{value: `<a href="//tosomewhere.com">to somewhere</a>`}}
  />
);

Describe alternatives you’ve considered There really aren’t any alternatives that can work for me here. The currently supported method of using components with Trans and index-based replacement is not feasible for how our company does translations. Additionally, it’s overly complicated when, for React, we can just use React.isElement and avoid creating those children in mapAST in Trans. This would be tougher for useTranslation because t is just i18next.getFixedT and thus isn’t prepared to handle React-specific stuff.

I think allowing ReactNode for Trans would be a simple and very useful alternative to the tightly proscribed way that is currently supported.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bfrickacommented, Sep 25, 2019

I would like to take a stab at this, for sure. Additionally, I think there is some complexity within renderNodes that can potentially be streamlined without breaking any of the logic or incurring performance penalties. As far as using components vs values, I’ll have to see. For example, having translations like: "Sometime in the year <year>B.C.E</year>" is strange to me compared to "Sometime in the year {{ year }} B.C.E".

0reactions
jamuhlcommented, Oct 24, 2019

closing in favor to #833

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Pass Values Inside Attributes in React | Pluralsight
In this guide, you will learn how to pass static and dynamic values to the attribute and create a custom attribute for the...
Read more >
The React.ReactNode type is a black hole - Changelog
ReactNode was accidentally getting passed an object of class TranslatedText which could not render. This is exactly the sort of bug we would ......
Read more >
Pass react component as props - Stack Overflow
Using this.props.children is the idiomatic way to pass instantiated components to a react component const Label = props => <span>{props.children}</span> ...
Read more >
React component as prop: the right way™️
Exploring how to pass React components as props, why we would want to ... First, we need to give the icon the default...
Read more >
How Children Types Work In React 18 And TypeScript 4
React treats children with just a little bit of magic that allows for ... more restrictive than ReactNode in what can be passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found