【发布时间】:2021-09-23 00:28:56
【问题描述】:
我是 react native 的新手,我有一个关于函数导出的问题,特别是默认应用程序的导出。
我见过两种导出方式,第一种是:
export default function App() {
return (/*Code goes in here and it renders*/);
}
自动渲染里面的任何代码,另一个是通过创建一个类组件,像这样
class App extends Component {
/*functions like componentDidMount() can go in here/*
render() { /*now the rendering code goes in here}
}
export default App;
这两种导出默认应用的方式有什么区别?是不是第一个只能返回基本代码,而第二个可以定义状态并创建像componentDidMount()这样的函数?或者你可以在两者中做同样的事情,但这只是一种声明方式?
感谢您在解释此事时花费时间和考虑。
【问题讨论】:
-
这是在 react 中定义组件的两种不同方式。第一个是函数组件,第二个是类组件。
标签: react-native function components