在 React Native 中导出带有代码的默认功能应用程序的方法
ways of exporting the default function app with code inside in react native
我是 React Native 的新手,我有一个关于函数导出的问题,特别是默认应用程序的导出。
我见过两种导出方式,第一种是:
export default function App() {
return (/*Code goes in here and it renders*/);
}
它自动渲染里面的任何代码,另一个是通过创建一个 class 组件,像这样
class App extends Component {
/*functions like componentDidMount() can go in here/*
render() { /*now the rendering code goes in here}
}
export default App;
这两种导出默认应用的方式有什么区别?是不是第一个只能 return 基本代码,而第二个可以定义状态并创建像 componentDidMount()
这样的函数?或者你可以在两者中做同样的事情,但它只是一种声明方式?
感谢您花时间和考虑来解释这件事。
您正在定义不同类型的组件。
第一个是功能组件,用函数定义。
第二个是 class 组件,定义为 class。
更多关于它们的区别可以查看https://www.geeksforgeeks.org/differences-between-functional-components-and-class-components-in-react/或google。
我是 React Native 的新手,我有一个关于函数导出的问题,特别是默认应用程序的导出。
我见过两种导出方式,第一种是:
export default function App() {
return (/*Code goes in here and it renders*/);
}
它自动渲染里面的任何代码,另一个是通过创建一个 class 组件,像这样
class App extends Component {
/*functions like componentDidMount() can go in here/*
render() { /*now the rendering code goes in here}
}
export default App;
这两种导出默认应用的方式有什么区别?是不是第一个只能 return 基本代码,而第二个可以定义状态并创建像 componentDidMount()
这样的函数?或者你可以在两者中做同样的事情,但它只是一种声明方式?
感谢您花时间和考虑来解释这件事。
您正在定义不同类型的组件。
第一个是功能组件,用函数定义。
第二个是 class 组件,定义为 class。
更多关于它们的区别可以查看https://www.geeksforgeeks.org/differences-between-functional-components-and-class-components-in-react/或google。