学习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>
);
}
}