Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Does react-transform-hmr support pure function components #6

Closed
dlmanning opened this issue Sep 20, 2015 · 12 comments
Closed

Does react-transform-hmr support pure function components #6

dlmanning opened this issue Sep 20, 2015 · 12 comments

Comments

@dlmanning
Copy link

I'm not having any luck getting components defined as a pure function to hot-reload. The component in question:

export default function Light (props) {
  const { light, toggleLight, id } = props
  const status = light.state.on ? 'one' : 'off'

  return (
    <div>{light.name}
      <button onClick={() => toggleLight({ ...light, id })}>
        {status}
      </button>
    </div>
  )
}

I get this error in the console:

[HMR] Updated modules:
(index):25734 [HMR]  - ./app/components/light.js
(index):25734 [HMR]  - ./app/components/lights.js
(index):25739 [HMR] App is up to date.
(index):15049 Uncaught TypeError: Cannot read property '__reactAutoBindMap' of null

Is this scenario supposed to work? Any idea what I'm doing wrong? Let me know if more context is needed.

@dlmanning dlmanning changed the title Does react-transform-hrm support pure function components Does react-transform-hmr support pure function components Sep 20, 2015
@gaearon
Copy link
Owner

gaearon commented Sep 21, 2015

Not currently.

gaearon/react-proxy#12
gaearon/babel-plugin-react-transform#17

If you'd like to work on this let me know :-)

@dlmanning
Copy link
Author

@gaearon : Thanks! I'll look into it and try to evaluate whether I have the time to dig into that.

Also wanted to say that everyone on my team really appreciates the work you've done for the community this year. Thanks! You've made all of our jobs easier and more fun.

@SpainTrain
Copy link

You've made all of our jobs easier and more fun.

Not on his team, but 👍 that

@ghost
Copy link

ghost commented Sep 29, 2015

@gaearon I'd like to work on this. I'm about to start transitioning almost all of our components over to pure components so this would be handy :)

@onemanstartup
Copy link

@gaearon will it be possible with that to hot-reload component when changing getDefaultProps?

@gaearon
Copy link
Owner

gaearon commented Sep 29, 2015

will it be possible with that to hot-reload component when changing getDefaultProps?

I'm a bit confused—how are default props related to pure function components?

@danmartinez101

I'd like to work on this. I'm about to start transitioning almost all of our components over to pure components so this would be handy :)

I have some preliminary work in a branch, give me a few days and I'll try to push something to get started.

@onemanstartup
Copy link

@gaearon dunno :) I just wanted the feature and wanted to ask. When component pure and you change getDefaultProps it is not reloaded :(

@gaearon
Copy link
Owner

gaearon commented Sep 29, 2015

@onemanstartup

We don't currently support pure components at all. If it works for you, it's probably by accident. This is what this issue is about. 😉

I'm also not sure what getDefaultProps is. For pure components, as well as for ES6 classes, there is no getDefaultProps()—only static defaultProps.

bebraw added a commit to survivejs/react-book that referenced this issue Oct 8, 2015
Sadly HMR isn't supported yet defeating the point...

Related: gaearon/react-transform-hmr#6 .
bebraw added a commit to survivejs/react-book that referenced this issue Oct 15, 2015
Sadly HMR isn't supported yet defeating the point...

Related: gaearon/react-transform-hmr#6 .
bebraw added a commit to survivejs/react-book that referenced this issue Oct 21, 2015
Sadly HMR isn't supported yet defeating the point...

Related: gaearon/react-transform-hmr#6 .
@wmertens
Copy link

Just pointing out for interested parties that current development of this feature is happening in gaearon/babel-plugin-react-transform#34 - it's already mostly working it seems.

@gaearon
Copy link
Owner

gaearon commented Mar 6, 2016

Please track this in gaearon/babel-plugin-react-transform#57.

@gaearon gaearon closed this as completed Mar 6, 2016
@gaearon
Copy link
Owner

gaearon commented Apr 18, 2016

React Hot Loader 3 supports functional components without destroying the state.
It supersedes both React Hot Loader and React Transform, and is built on lessons learned from both.
Check it out: gaearon/react-hot-boilerplate#61

@linus-amg
Copy link

hi @gaearon awesome project, congratulations. though im not developing with react i got inspired to use hmr in a backbone project i've got, im using gulp + rollupify + babelify + hbsfy + browserify + browserify-hmr plugin, now i wanted to see how i could implement a transform to re-render my views or templates, would you know of an easier starting point then react-transform-hmr?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants