请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

关于新初始化的RN项目的模板代码的问题

const App: () => React$Node = () => {
return (
<>

  </SafeAreaView>
</>

);
};
而不是

export default class App extends Component {
render() {
const {navigation} = this.props;

return (
  <View style={styles.container}>
    <Button
      title={'FastListDemo'}
      onPress={() => navigation.navigate('FastListDemo')}
    />
  </View>
);

}
}

正在回答 回答被采纳积分+3

1回答

CrazyCodeBoy 2019-12-08 19:45:24

新初始化的项目都会自动生成一个预览界面的模板代码,这个模板代码会随着RN的不同版本的发布而不同。

问题1:这个模板可以删吗?

答:可以

问题2:是按照这个模板写还是按照课程中推荐的方式写呢?

答:建议按照课程中推荐的方式写也就是通过标准的component的方式写。

如:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
export default class App extends Component{
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}> to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});


1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信