GithubHelp home page GithubHelp logo

Comments (5)

gaearon avatar gaearon commented on June 10, 2024

Webpack hot module updates follow the import chain. As long as a module “ends up” being imported from components only, hot updates will work. If a specific module import chain ends in something like index.js which is not a component, hot updates will fail because react-transform-hmr has no idea how to handle updates to something other than components.

That said you can write manual code to handle hot updates of modules that don’t end up consumed by components. For example, this is how we hot replace reducers in Redux.

from react-transform-boilerplate.

tedpennings avatar tedpennings commented on June 10, 2024

Is there a way to plugin to the React HMR features to extend it and make it aware of my code?

I'm working on code that reads config in JSON and creates React elements on the fly, so the HMR proxying doesn't work. I basically have a top-level function that returns a React Router element, which delegates to functions that create React component classes through currying. My goal is changes the JSON configuration file triggering hot updates to the React app produced by that json->react transform function.

If this use case isn't a good fit for React HMR, that's a totally reasonable answer -- I've considered implementing json config->React app as a compile-time transform (probably as a webpack loader for the JSON config file).

from react-transform-boilerplate.

gaearon avatar gaearon commented on June 10, 2024

Do you care about preserving component local state (this.state) on hot reloads? If not, just don’t use proxying and use raw HMR API to replace the whole component subtree with a new version like here.

from react-transform-boilerplate.

tedpennings avatar tedpennings commented on June 10, 2024

Oh that's awesome and exactly what I need, thanks!
On Mar 5, 2016 12:42 PM, "Dan Abramov" [email protected] wrote:

Do you care about preserving component local state (this.state) on hot
reloads? If not, just don’t use proxying and use raw HMR API to replace the
whole component subtree with a new version like here
reduxjs/redux#1455.


Reply to this email directly or view it on GitHub
#120 (comment)
.

from react-transform-boilerplate.

donaldpipowitch avatar donaldpipowitch commented on June 10, 2024

Thank you for your answer.

from react-transform-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.