Search code examples
react-nativeexpo

How to define entry point for react native app


I'm just getting started with react native and have created a base app with create-react-native-app.

I did some restructuring and made a few new folders and renamed the App.js to Home.js. I modified the app.json to contain an entry point that references the new Home.js file. When I load the app, nothing happens. There's no error, it just stays on the expo screen.

.
 -components
 -screens
    -Home
        Home.js
 -config
 -node_modules
 -tests
 app.json

app.json file:

{
  "expo": {
    "sdkVersion" : "23.0.0",
    "entryPoint" : "./screens/Home/Home.js"
  }
}

How do you define the entry point of the app?


Solution

  • if you are using Expo, you have to specify the entrypoint in your app.json file like this:

    {
      "expo": {
        "entryPoint": "./src/app/index.js"
      }
    }
    

    then, inside that file you need to register the app with Expo.registerRootComponent(YOUR_MAIN_APP_COMPONENT)

    import Expo from 'expo'
    ...
    
    class App extends Component {
      ...
    }
    
    export default Expo.registerRootComponent(App);
    

    this way you can add your entry file wherever you want.