LoginSignup
1

More than 5 years have passed since last update.

Raw Text "" must be wrapped in an explicit Text component

Posted at

スクリーンショット 2017-02-10 13.39.29.png

React Native開発中に出くわしたエラー。
JSXでStringをそのまま{}&&で判定して、真であればコンポーネントを表示しようとしている箇所で起きている。

{this.state.showText &&
  <Text>{this.state.showText}</Text>
}

this.state.showTextが""(空文字列)の場合、そのまま評価されてしまって上記のエラーとなっている。

対処

!!で文字列の真偽を判定する。

{!!this.state.showText &&
  <Text>{this.state.showText}</Text>
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1