This plugin is used to automatically introduce the second parameter in umi
's useModel
, removing the unused value and avoiding the performance loss caused by repeated rendering of the component.
English | 简体中文
npm i babel-plugin-umi-model --save-dev
or
pnpm add babel-plugin-umi-model -D
import { useModel } from "umi";
const { userInfo, token } = useModel("user");
⬇️
import { useModel } from "umi";
const { userInfo, token } = useModel("user", (model) => ({
userInfo: model.userInfo,
token: model.token,
}));
This configuration is common to umi3
and umi4
versions
Remember to configure the .env
file with BABELRC=true
{
"plugins": [
"umi-model"
]
}
This configuration is common to umi3
and umi4
versions
import { defineConfig } from "umi";
// import BabelPluginUmiModel from 'babel-plugin-umi-model'
export default defineConfig({
extraBabelPlugins: [
"umi-model",
// [
// "umi-model",
// {
// extensions: [".jsx", ".tsx"],
// excludes: ['node_modules', 'src/.umi', 'src/.umi-production'],
// },
// ],
// ],
// BabelPluginUmiModel
],
});
import { defineConfig } from "umi";
export default defineConfig({
plugins: ["./plugin-test"],
});
import { IApi } from "umi";
export default (api: IApi) => {
api.addBeforeBabelPlugins(() => {
return ["umi-model"];
});
};
- Type:
string[]
- Default:
['.jsx', '.tsx']
- Type:
string[]
- Default:
['node_modules', 'src/.umi', 'src/.umi-production']