学习RN过程中看到的几种组件声明的写法,仅此记录,如有问题还需各位看官指正,谢谢;

1.react-native init 项目 自动生成的App.js
const App: () => React$Node = () => {
  return (
    <View>
      <Text>测试</Text>
    </View>
  );
};
export default App;
2.导出组件网上还看到使用export{App as default};
const App: () => React$Node = () => {
  return (
    <View>
        <Text>测试</Text>
    </View>
  );
};
export { App as default };
3.使用ES6的class关键字来创建React组件,并在创建组件时导出组件,一气呵成,代码可读性高一些
export default class App extends React.Component {
  render() {
    return (
      <View>
        <Text>测试</Text>
      </View>
    );
  }
}
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐