LoginSignup
3
1

More than 5 years have passed since last update.

【React Native】Cannot Add a child that doesn't have a YogaNode to a parent with out a measure function

Posted at

エラー内容

Cannot Add a child that doesn't have a YogaNode to a parent with out a measure function
iOSでは発生せず、Androidのみ発生。

原因

エミュレータやネイティブ環境には原因がなく、実装上の問題
<Text>で囲まれていない文字列がある場合に発生。

今回の場合

  • ボタンクリックでコンポーネントを表示したい => デフォルトで非表示になる子コンポーネントを作成
  • 子コンポーネントはフラグによって''を返す => アウト

アウト

例:パスワード表示/非表示にするtoggle

const SubComponent = (props: togglePasswordProps) => {
  const {
    style, name, togglePassword,
  } = props;

  if (name !== NAMES.PASSWORD) return ``;

  return (
    <TouchableOpacity
       onPress={togglePassword}
    >
      <Text style={style}>表示</Text>
    </TouchableOpacity>
  );
};

OK

例:パスワード表示/非表示にするtoggle

const SubComponent = (props: togglePasswordProps) => {
  const {
    style, name, togglePassword,
  } = props;

-  if (name !== NAMES.PASSWORD) return ``;
+  if (name !== NAMES.PASSWORD) return null;

  return (
    <TouchableOpacity
       onPress={togglePassword}
    >
      <Text style={style}>表示</Text>
    </TouchableOpacity>
  );
};

参考

3
1
0

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
3
1