Search code examples
eslintreact-nativepure-function

Component should be written as a pure function


I have a react-native android application. My component in index.android.js is stateless so eslint is throwing the error "Component should be written as a pure function". If I make the component as pure function, how do i register the application or how should the instantiation be?


Solution

  • You can register the application even with a "pure function" This kind of code would work

     const App = () => {
      return (
        <MainApp />
      );
    };
    
    AppRegistry.registerComponent('myapp', () => App);
    

    The "return" part can be deleted for a cleaner code:

    const App = () => (
        <MainApp />
    );
    
    
    AppRegistry.registerComponent('myapp', () => App);