我在 webpack-dev-middleware 上遇到了一些麻烦,而不是使用 react 无状态函数进行热重载,但是如果我创建一个类扩展组件,它就可以正常工作。
例如,这非常有效。
// home.js
import React from 'react'
export default class Home extends React.Component {
render() {
return (
<div>
<h1>Drop it like it's hot</h1>
</div>
)
}
}
然而,这失败得很惨。
// home.js
import React from 'react'
export default function Home() {
return (
<div>
<h1>Hello World</h1>
</div>
)
}
错误:
[Warning] [HMR] The following modules couldn't be hot updated: (Full reload needed) (bundle.js, line 1742)
This is usually because the modules which have changed (and their parents) do not know how to hot reload themselves. See http://webpack.github.io/docs/hot-module-replacement-with-webpack.html for more details.
[Warning] [HMR] - ./client/components/home.js (bundle.js, line 1750)