HMR plugin for dva without babel inspired by babel-plugin-dva-hmr and react-hot-loader.
$ npm install dva-hot
Patch App
import hot from 'dva-hot'
import dva from 'dva'
const app = dva()
hot.patch(app) // you must patch `app` before calling app.{model,router,start}
app.model(require('./models/a').default)
app.model(require('./models/b').default)
app.router(require('./router').default)
app.start('#root')
After [email protected]
, the usage below should work:
import hot from 'dva-hot'
import dva from 'dva'
import { createElement } from 'react'
import { render } from 'react-dom'
const app = dva()
hot.patch(app) // you can pass container to hot.patch like `hot.patch(app, container)`
app.model(require('./models/a').default)
app.model(require('./models/b').default)
app.router(require('./router').default)
// After [email protected]: pass container for HMR
render(createElement(app.start()), hot.setContainer('#root'))
// or
// render(createElement(app.start()), hot.setContainer(document.querySelector('#root')))
Self-accepted Router
import React from 'react'
import { routerRedux } from 'dva/router'
import { renderRoutes } from 'react-router-config'
import hot from 'dva-hot'
import routes from '../routes'
const { ConnectedRouter } = routerRedux
function RouterConfig({ history }) {
return <ConnectedRouter history={history}>{renderRoutes(routes)}</ConnectedRouter>
}
export default hot.router(module)(RouterConfig)
Self-accepted Model
import hot from 'dva-hot'
export default hot.model(module)({
namespace: 'a-dva-model'
state: [],
// upgrade to [email protected] if you use models that without `reducers`
})