gpt4 book ai didi

javascript - webpack 2 热重载不重新渲染

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:04 25 4
gpt4 key购买 nike

我正在做一个 Universal React 项目,我的客户端入口点是:

import React from 'react'
import {render} from 'react-dom'
import {Provider} from 'react-redux'
import {AppContainer} from 'react-hot-loader'
import {Router, browserHistory} from 'react-router'
import {syncHistoryWithStore} from 'react-router-redux'
import {addLocaleData} from 'react-intl'
import it from 'react-intl/locale-data/it'
import en from 'react-intl/locale-data/en'
import IntlProvider from 'shared/containers/IntlProvider'
import configureStore from 'shared/configureStore'
import routes from 'shared/routes'
import {isDev, isLive} from 'shared/config'

[en, it].forEach(addLocaleData)

const hook = document.getElementById('app')
const initialState = JSON.parse(hook.getAttribute('data-initial-state'))
const store = configureStore(initialState)
const history = syncHistoryWithStore(browserHistory, store)
let content = (
<Provider store={store}>
<IntlProvider key="intl">
<Router history={history}>
{routes}
</Router>
</IntlProvider>
</Provider>
)

if (isLive) {
content = <AppContainer>{content}</AppContainer>
}

function renderApp() {
render(content, hook)
}

if (isLive) {
module.hot.accept('./index.js')
module.hot.accept('../shared/routes', renderApp)
}

renderApp()

在组件更改时,重新加载似乎有效,但没有应用渲染。也许它发生在热重载技巧发生之前?

console output

注意我的路由配置目前是经典的非动态路由。

最佳答案

我有同样的问题,因为我只是忘了添加替换模块的代码

if (module.hot) {
module.hot.accept(
"./App",
() => {
const NextApp = require("./App").App; // THIS LINE
render(NextApp);
},
);

关于javascript - webpack 2 热重载不重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39202750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com