React Native Text Component render errors

Aboa·2023년 3월 17일

react native Error: Text strings must be rendered within a <Text /> component
"vscode" does not display errors, it can only be checked during the rendering process, so I summarized the various types that I found.

1. Space between components

<View> <Text>Hello</Text> </View>

delete the space


2. Logical operators rendering

{list.length && (
  <View />
)}

list.length value is 0, so it renders 0.

const text = "";
{text && (
  <View />
)}

text value is "", so it renders "".

const count = 0;
{count && (
<View />
)}

count value is 0, so it renders 0.

const count = 0;
{!!count && (
  <View />
)}

If you want to render it only if there is a value, write the !! on front

0개의 댓글