React-native-web: <View> breaks if it contains a boolean (false) child

Created on 6 Nov 2017  路  1Comment  路  Source: necolas/react-native-web

A common shorthand for handling potentially empty state / prop entries is:

<View>{this.state.foo && <Text>{this.state.foo}</Text>}</View>

With the latest version (0.1.13) this construct breaks the View with the error message:

A text node cannot be a child of a <View>.

The test in View/index.js tests for typeof item !== 'string', so the error message makes sense, however I think the behavior is unexpected, as passing a false value means (to me at least) "don't render anything".

Before opening a PR, however, I wanted to make sure that this isn't a desired behavior, and if so, what is the alternative syntax to passing a possibly empty value as a child?

  • React Native for Web (version): 0.1.13
  • React (version): 16.0.0

Most helpful comment

My bad, our code is passing an empty string, not false.

>All comments

My bad, our code is passing an empty string, not false.

Was this page helpful?
0 / 5 - 0 ratings