JSX表达式必须有一个父元素。ts(2657)

huangapple go评论93阅读模式
英文:

JSX expressions must have one parent element.ts(2657)

问题

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>打开 App.js 开始你的应用开发</Text>
      <StatusBar style="auto" />
    </View>
    
    <View>
      <Text>ffff</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'red',
  },
});
英文:

i am using React Native, i am freshman there , what is the problem here: mistake is there
i am using React Native, i am freshman there , what is the problem here: mistake is there
i am using React Native, i am freshman there , what is the problem here: mistake is there
i am using React Native, i am freshman there , what is the problem here: mistake is there
i am using React Native, i am freshman there , what is the problem here: mistake is there
i am using React Native, i am freshman there , what is the problem here: mistake is there

import React from &#39;react&#39;;
import { StyleSheet, Text, View } from &#39;react-native&#39;;

export default function App() {
  return (
  


    &lt;View style={styles.container}&gt;
      &lt;Text&gt;Open up App.js to start working on your app!&lt;/Text&gt;
      &lt;StatusBar style=&quot;auto&quot; /&gt;
    &lt;/View&gt;

    &lt;View &gt;
&lt;Text&gt;ffff&lt;/Text&gt;
      &lt;/View&gt;
 
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: &#39;#fff&#39;,
    alignItems: &#39;center&#39;,
    justifyContent: &#39;center&#39;,
    backgroundColor: &#39;red&#39;,
  },
});

答案1

得分: 0

import React from 'react';
import { StyleSheet, Text, View, StatusBar } from 'react-native';

export default function App() {
  return (
    <>
      <StatusBar barStyle="dark-content"/>
      <View style={styles.container}>
        <Text>打开 App.js 开始开发您的应用</Text>
      </View>

      <View >
        <Text>ffff</Text>
      </View>
    </>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'red',
  },
});
英文:

You've to wrap up your content in a parent section or view like this:

import React from &#39;react&#39;;
import { StyleSheet, Text, View, StatusBar } from &#39;react-native&#39;;

export default function App() {
  return (
    &lt;&gt;
      &lt;StatusBar barStyle=&quot;dark-content&quot;/&gt;
      &lt;View style={styles.container}&gt;
        &lt;Text&gt;Open up App.js to start working on your app!&lt;/Text&gt;
      &lt;/View&gt;

      &lt;View &gt;
        &lt;Text&gt;ffff&lt;/Text&gt;
      &lt;/View&gt;
    &lt;/&gt;
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: &#39;#fff&#39;,
    alignItems: &#39;center&#39;,
    justifyContent: &#39;center&#39;,
    backgroundColor: &#39;red&#39;,
  },
});

huangapple
  • 本文由 发表于 2020年10月22日 14:09:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64476268.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定