-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support textComponent="" to render raw strings on web #1330
Comments
Actually I believe internally React creates Fragment if you just return raw string. After making a change locally & adding a test, this comes up:
logs out |
If anyone can verify that'd be great. |
Also raw text returns might get messy when inserting JSX via |
I think react 16 supports returning array of children. |
Yes it does, but that requires a key on each element (I don't know how it behaves when there are plain strings in the array). |
Yeah it'll trigger a warning but it might be ok? I don't have a strong opinion on this tbh. |
I'd prefer not to trigger React warnings inside a React library. However I think we could get along with just using the elements indices (see #1204) in our case, because there won't be a reordered rendering of the same elements for 99.9% of the use cases. But now I wonder what it behaves like if you mix strings/components in an array... 🤣 |
I think that's an existing issue already right? (if |
Un-keyed components in the return React.createElement(textComponent, null, ...nodes) What I wonder about is how React would handle things like: return [
'Hello ',
<b>World</b>
] Are keys in this case only required for the React elements (e.g. |
Here we go: CodeSandbox showing you only need to put indices on non-string elements returned in an array. @longlho I'd prefer this over |
The only reason we kept |
We should probably keep RN support... |
we'd still support RN, just that RN users would have to manually set |
Detecting it and setting the root |
that might just be overkill in terms of complexity. I think keeping it as |
Just a note that right now it's not possible to use Example:
Error:
|
hmm interestingly |
See #987 and particularly #987 (comment) and subsequent comments. We can avoid allocating an additional React.Fragment if the user specifically chooses the empty string (or perhaps
"string"
orString
?) as thetextComponent
.The text was updated successfully, but these errors were encountered: