gpt4 book ai didi

javascript - React Native 中的逗号和解析错误

转载 作者:行者123 更新时间:2023-11-27 22:33:26 25 4
gpt4 key购买 nike

尝试使用我在 YouTube 等上找到的教程来学习 React Native。然而,自从这些教程发布以来,语法似乎已经发生了很大的变化。

目前,我收到 requireTrailingComma: Missing comma before close curlybranch 错误。但是当我在大括号之前放置一个逗号时,它们会告诉我 parseError Unexpected token.

ViewContainer.js 代码:

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

class ViewContainer extends Component {
render() {
return (
<View style={styles.viewContainer}>
{this.props.children}
</View>
);
}
}

const styles = React.Stylesheet.create({

viewContainer: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'stretch',
} <TIS IS WHERE I'M GETTING THE ERROR>

});

module.exports = ViewContainer;

index.ios.js 代码:

'use strict'
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import ViewContainer from './app/components/ViewContainer';

class Project extends Component {
render() {
return (
<ViewContainer>
<Text>{'Hello from inside ViewContainer'}</Text>
</ViewContainer>
);
}
}

const styles = StyleSheet.create({
});

AppRegistry.registerComponent('Project', () => Project);

我做错了什么?

最佳答案

错误说明了一切,只需在大括号后面添加一个逗号即可。

    alignItems: 'stretch',
}

 alignItems: 'stretch',
},

  alignItems: 'stretch' 
}

关于javascript - React Native 中的逗号和解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39355936/

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