1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Reload the Simulator when Changes Occur in React Native Apps

    react-nativeReact Native
    javascriptJavaScript
    androidAndroid
    iosiOS

    Once your React Native app is up and running, we’ll make a simple change and reload the simulator to show the change. We’ll look at manually reloading the simulator, reloading with Live Reload and reloading with Hot Reloading, and talk about the pros and cons of each method.

    Code

    Code

    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: Open index.js, which is the entry point for the React Native app. The app registry is used to load a React component onto the screen. The component that is being loaded is app. Let's open app.js. Now you can see the component that is being shown on the simulator.

    Let's clean this up a bit and remove the parts of the default component that we aren't using. We can change the welcome text to "restaurant review." To see the change in the simulator, we don't need to rebuild the entire app. Instead, for iOS, select the simulator and press command-R on a Mac or control-R on Windows, which will rebuild just the JavaScript portion of the app. We can see that change.

    Another way to refresh the app is to open the developer menu with command-D on a Mac or control-D on Windows and select reload. On Android, you can double-tap R to reload or bring up the developer menu with command-M on a Mac or control-M on Windows and select reload.

    There's another way to reload and see changes on both iOS and Android as well. Open the developer menu and enable live reload. In this mode, a watcher will watch the files in your project. Saving any JS file will trigger the simulator to reload the app.

    We can take this one step further as well. First, turn off live reload, and then enable hot reloading. In hot reloading mode, the app won't rebuild and reload the entire JavaScript bundle. Instead, it will just update the parts of the app that you changed.

    It will reload the components without a full refresh. When we make changes now, you can see that it's hot reloading without refreshing the entire bundle. Hot reloading can save a lot of time when you're developing, but sometimes it doesn't work very well. Then you have to go back to a full refresh. For that reason, we'll switch off hot reloading for this app.