Closed smirea closed 7 years ago
the following keeps state between HMR updates:
import {withJob} from 'react-jobs'; @withJob(() => Promise.resolve()) export default class Foo extends React.Component { state = {rand: Math.random() * 1000; } render () { return <div>seed: {this.state.rand}</div>; } }
however, the following loses state:
import {withJob} from 'react-jobs/ssr'; @withJob(() => Promise.resolve()) export default class Foo extends React.Component { state = {rand: Math.random() * 1000; } render () { return <div>seed: {this.state.rand}</div>; } }
I suspect it's due to this line: https://github.com/ctrlplusb/react-jobs/blob/master/src/ssr/withJob.js#L98
for the SSR version, you are creating 2 wrappers, but only exporting 1 of them. HMR needs to bind to every wrapped component in order for state to be preserved
This seems to be working in the latest API release.
Example here: https://github.com/ctrlplusb/react-universally/tree/%40next/react-jobs
Edit the JobRenderer I created within the JobsRoute.js file.
JobRenderer
JobsRoute.js
the following keeps state between HMR updates:
however, the following loses state:
I suspect it's due to this line: https://github.com/ctrlplusb/react-jobs/blob/master/src/ssr/withJob.js#L98
for the SSR version, you are creating 2 wrappers, but only exporting 1 of them. HMR needs to bind to every wrapped component in order for state to be preserved