【发布时间】:2016-07-08 20:29:38
【问题描述】:
我在 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)
【问题讨论】:
-
AFAIK,因为它只是一个函数,所以很难静态确定它是react组件还是函数(上面的问题提到了)
-
不行,项目的README里有提到。
-
感谢您的回复!
标签: reactjs webpack react-hot-loader webpack-hot-middleware