利用react-hot-loader实现局部更新,webpack也有热加载,但跟react-hot-loader还是不一样的。webpack是代码修改后,自动渲染整个页面。react-hot-loader是不在改变状态的前提下,局部渲染
npm install --save-dev react-hot-loader
"scripts":{"start": "webpack-dev-server --hot"}
或配置文件里设置 hot:true
devServer: {hot: true}
plugins: [new webpack.HotModuleReplacementPlugin()
react-hot-loader/patch必须放在entry第一位,如果第一位必须是polyfill,就放第二位
entry: ['babel-polyfill','react-hot-loader/patch'__dirname + '/app/apps'
在.babelrc或babel.config.js里配置plugins
{"plugins": ["react-hot-loader/babel"]}
如果主入口文件是app/index.js
将顶级组件都包含在<AppContainer>中,注意<AppContainer>只能包含一个React组件
import React from 'react';import { render } from 'react-dom';import { AppContainer } from 'react-hot-loader';import Root from './containers/Root';import { configureStore, history } from './store/configureStore';import './app.global.css';const store = configureStore();render(<AppContainer><Root store={store} history={history} /></AppContainer>,document.getElementById('root'));if (module.hot) {module.hot.accept('./containers/Root', () => {// eslint-disable-next-line global-requireconst NextRoot = require('./containers/Root').default;render(<AppContainer><NextRoot store={store} history={history} /></AppContainer>,document.getElementById('root'));});}
OK,通过上面五步就可以配置成功了
ant.design 4.x获取form表单的方式
ant.design v5 and 中如何在class中使用umijs的useModel调用initialState
react之ref提示:Using string literals in ref attributes is deprecated,不能使用字符串,怎么处理?
react不能在 render里设置state,也不能在componentWillReceiveProps里设置state,会导致性能问题。如果要通过属性改变state,怎么做呢?可以利用getDerivedStateFromProps生命周期函数
Next.js 是一个轻量级的 React 服务端渲染应用框架。
通过箭头函数或bind方式,对绑定事件传参
React Hot Loader是一个插件,允许React组件在不丢失状态的情况下进行实时重新加载。它适用于Webpack和其他支持热模块替换(HMR)和Babel插件的捆绑器
Warning: `getFieldDecorator` will override `value`, so please don't set `value` directly and use `setFieldsValue` to set it.
React 的核心思想是:封装组件。 各个组件维护自己的状态和 UI,当状态变更,自动重新渲染整个组件。 基于这种方式的一个直观感受就是我们不再需要不厌其烦地来回查找某个 DOM 元素,然后操作 DOM 去更改 UI