组件应该写成一个纯函数
Component should be written as a pure function
我有一个本机反应 android 应用程序。我在 index.android.js 中的组件是无状态的,所以 eslint 抛出错误 "Component should be written as a pure function"。如果我将组件作为纯函数,我该如何注册应用程序或者应该如何实例化?
您甚至可以使用 "pure function" 注册应用程序
这种代码可以工作
const App = () => {
return (
<MainApp />
);
};
AppRegistry.registerComponent('myapp', () => App);
可以删除 "return" 部分以获得更清晰的代码:
const App = () => (
<MainApp />
);
AppRegistry.registerComponent('myapp', () => App);
我有一个本机反应 android 应用程序。我在 index.android.js 中的组件是无状态的,所以 eslint 抛出错误 "Component should be written as a pure function"。如果我将组件作为纯函数,我该如何注册应用程序或者应该如何实例化?
您甚至可以使用 "pure function" 注册应用程序 这种代码可以工作
const App = () => {
return (
<MainApp />
);
};
AppRegistry.registerComponent('myapp', () => App);
可以删除 "return" 部分以获得更清晰的代码:
const App = () => (
<MainApp />
);
AppRegistry.registerComponent('myapp', () => App);