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

Error: Text strings must be rendered within a <Text> component. #31273

Closed
darda-ergo opened this issue Mar 30, 2021 · 10 comments
Closed

Error: Text strings must be rendered within a <Text> component. #31273

darda-ergo opened this issue Mar 30, 2021 · 10 comments
Labels
Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@darda-ergo
Copy link

darda-ergo commented Mar 30, 2021

image

@darda-ergo
Copy link
Author

Solved. need to use ternary operator

@ezranbayantemur
Copy link

Hello, looks like you found the solution!
Can you close the issue if you done with it?

@anhkieet
Copy link

use !!imageUri &&

@chrisbobbe
Copy link

chrisbobbe commented Apr 14, 2021

Looks like the string it's complaining about is the empty string at imageUri.

The error is intentional; it's not obvious that this is a bug in React Native, and you've found a solution. Seems like the issue should be closed.

@karlhorky
Copy link

Do empty strings still cause this Text strings must be rendered within a <Text> component error message?

I can't seem to reproduce this (on Snack with Expo). The following does not cause crashes:

export default function App() {
  const name = '';
  return (
    <View style={styles.container}>
      {name && <Text>name: {name}</Text>}
      {''}
      <Text>no crashes</Text>
    </View>
  );
}

https://twitter.com/karlhorky/status/1576958348288987137

@karlhorky
Copy link

Seems like they do not cause issues anymore with React Native 0.70.1:

I just started a new React Native app just now (npx react-native init with react-native@0.70.1) to verify this and confirmed empty strings outside of <Text> components do not cause this error:

Screen Shot 2022-10-04 at 13 10 49

Whereas a string with content in it does:

Screen Shot 2022-10-04 at 13 14 34

@karlhorky
Copy link

Empty strings indeed no longer cause errors (if you use React 18+):

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 16, 2023
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@fabOnReact
Copy link
Contributor

Do you still experience this issue?

I have four years of experience maintaining facebook/react-native and I specialize in the Text and TextInput components. I currently have 58 facebook/react-native PRs.

If you still experience this issue, I will prepare a patched release with the fix.

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

6 participants