Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how is hot reload supposed to work in react native?

Hot Reloading is out now but I am having lots of problems getting it to work.

At first I had the standard module.hot.accept("../reducers", () => { code in my redux store but that was causing problems. After commenting that code out I started getting Cannot read property 'length' of undefined.

I created a new project react-native init test and I get the same error every time a file is changed.

ExceptionsManager.js:61 Cannot read property 'length' of undefined

Is there something that needs to be done in the project to make hot reloading work?

Update

This is still undocumented and causing more problems than its worth. For now I am using redux-persist with live reloading.

like image 393
respectTheCode Avatar asked Mar 22 '16 19:03

respectTheCode


People also ask

How do you hot reload react native app?

First, run the app using react-native run-android on Terminal. Now, shake the Android device which has the running app. Then select the Enable Hot Reloading or Enable Live Reload option from the popup. Save this answer.

How are hot reloading and live reloading in react native different?

The difference between the two is, Live Reloading is gonna reload your entire application. It's just gonna be like, okay, the file changed, reload the entire app. Hot Reloading is not gonna reload your entire application. It's just going to patch the code that was changed and keep the state in your app.

What does Hot Reload do?

This feature was previously only available when starting the app without the debugger. CSS Hot Reload: You can change CSS files while the app is running, and changes are applied immediately to the running app as you type.

Does react use hot reload?

When editing a React component, React Fast Refresh will efficiently only update and re-render that component. This leads to significantly faster hot reload times. In addition, React Fast Refresh will preserve component state during re-renders so you won't need to manually create the same scenario again.


1 Answers

Facebook has finally documented how to use Hot Reloading or Hot Module Replacement.

https://facebook.github.io/react-native/blog/2016/03/24/introducing-hot-reloading.html

The api is slightly different than Webpack

if (module.hot) {
    module.hot.accept(() => {
        const nextRootReducer = require("../reducers").default;
        store.replaceReducer(nextRootReducer);
    });
}
like image 133
respectTheCode Avatar answered Nov 15 '22 07:11

respectTheCode