gpt4 book ai didi

javascript - React-Native 'Cannot add a child that doesn' t 有一个 YogaNode 到没有测量功能的 parent !

转载 作者:行者123 更新时间:2023-11-30 14:48:19 26 4
gpt4 key购买 nike

App.js 呈现可重用的外部组件 Fade及其子组件。 Fade中的动画当使用 {this.state.visible ? children : null} 确认 child 时执行在它的渲染函数中。调试后,我认为错误是由三元运算符引起的,因为它在 Fade 的渲染函数中定义的方式。 .

我的问题是我不知道如何在渲染中正确包装这个三元运算符。我试过<Text><View>没有成功。有谁知道如何解决这个问题?

提前谢谢你。

App.js 渲染

<Container>
<Fade visible={display.bus}> {renderIf(display.bus, <BusTemplate />)} </ Fade>
</Container>

Fade.js 渲染

<Animated.View style={this.state.visible ? combinedStyle : containerStyle}>
{this.state.visible ? children : null}
</Animated.View>

Bus.js 渲染

<Container>
<Image source={require("./scenerios/Bus.png")} style={styles.MainContainer}>
</Image>
</Container>

最佳答案

再见迭戈,一旦我读到这个问题与 if 检查 undefined 变量有关。 this.state.visible 可能是您的情况。
另一种方法是将您的组件包装在 View 标记中。
这是 if 检查的相关问题:
https://github.com/facebook/react-native/issues/13653
如果您已经解决了,请告诉我们如何解决

关于javascript - React-Native 'Cannot add a child that doesn' t 有一个 YogaNode 到没有测量功能的 parent !,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48565250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com