gpt4 book ai didi

react-native - react native : Cannot add a child that doesn't have a YogaNode or parent node

转载 作者:行者123 更新时间:2023-12-03 08:44:04 26 4
gpt4 key购买 nike

刚开始学习 react-native,

我创建了一个单独的文件 flexdemo.js 并创建了如下组件:

import React, { Component } from 'react';
import { View } from 'react-native';

export default class FlexibleViews extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 1, backgroundColor: "powderblue" }}> </View>
<View style={{ flex: 2, backgroundColor: "skyblue" }}> </View>
<View style={{ flex: 3, backgroundColor: "steelblue" }}> </View>
</View>

);
}
}

和 App.js 文件如下:
import React, { Component } from 'react';
import {
AppRegistry,
Platform,
StyleSheet,
Text,
View, Image
} from 'react-native';

// import Bananas from './src/banana';
// import LotsOfStyles from './src/styledemo'

import FlexibleViews from './src/flexdemo';

export default class App extends Component {
render() {
return (
// <Bananas name = "Tapan"/>
<View>
<FlexibleViews />
</View>

);
}
}

这给了我这个错误:

enter image description here

现在,如果我尝试通过将 flexdemo.js 代码添加到 App.js 来运行代码,那么一切正常。

像这样改变了 App.js:
import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

export default class FlexDimensionsBasics extends Component {
render() {
return (
// Try removing the `flex: 1` on the parent View.
// The parent will not have dimensions, so the children can't expand.
// What if you add `height: 300` instead of `flex: 1`?
<View style={{flex: 1}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}} />
<View style={{flex: 2, backgroundColor: 'skyblue'}} />
<View style={{flex: 3, backgroundColor: 'steelblue'}} />
</View>
);
}
}

enter image description here

最佳答案

删除组件内的注释。

关于react-native - react native : Cannot add a child that doesn't have a YogaNode or parent node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46605376/

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