Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Hot Reloading your React App

Jesus Mendoza
Jesus Mendoza
23,289 Points

Losing state of my application when using react-hot-loader

Hey guys,

I was following How to Setup Webpack for React workshop, and when I got to the hot-reload video I started getting a few errors (I think it's because react-hot-reload is out of date on the video). Anyway I made it work but now when it automatically reloads, I lose state... Any ideas?

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

var webpackConfig = {
    entry: path.join(__dirname, 'src/js/index.js'),
    output: {
        path: path.join(__dirname, 'build'),
        filename: 'bundle.js'
    },
    module: {
        loaders: [
// this is different now
            { loaders: ['react-hot-loader/webpack', 'babel'], test: /\.js$/, exclude: /node_modules/ },
            { loader: 'style!css!sass', test: /\.scss$/ }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, 'src/index.html')
        }),
// this is also different now
        new webpack.HotModuleReplacementPlugin()
    ]
};

module.exports = webpackConfig;