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

Not parsing when 2 variables #43

Closed
RaphArbuz opened this issue Feb 8, 2018 · 3 comments
Closed

Not parsing when 2 variables #43

RaphArbuz opened this issue Feb 8, 2018 · 3 comments

Comments

@RaphArbuz
Copy link

Strange thing:
<ParsedText ...>{a} {b}</ParsedText>
does not get parsed but
<ParsedText ...>{a + ' ' + b}</ParsedText>
does.
I don't know if it's a bug or if I'm doing something wrong.

Many thanks!

@thinklinux
Copy link

thinklinux commented Mar 19, 2019

The problem probably is that for react {a} {b} translates to three children like so ['a', ' ', 'b'] and {a + ' ' + b} is only one child which is just a simple string not an array of strings. I think the code is assuming that you have only one child inside <ParsedText>. I'm not sure that that's a bug tho. And you are not doing anything wrong for sure.

@fbartho fbartho removed the bug label Jun 11, 2020
@fbartho
Copy link
Contributor

fbartho commented Jun 11, 2020

This is a limitation of how React works. Depending on your exact code, I'd say you could use the latter pattern that you suggested in your issue description.

If you want, you can make a special component that uses the React.Children APIs to concatenate all the strings for you into a single component.

I'm going to close this ticket as it's over 2 years old, but if you think you still want to discuss it, we can reopen!

If you find a bug or have a PR, I'm working on a new release in #79

@fbartho fbartho closed this as completed Jun 11, 2020
@phatmann
Copy link

This should be documented clearly. Must be a single child! This cost me HOURS of head scratching!

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

No branches or pull requests

4 participants