Comments (5)
由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。
from umi.
只要接口返回的 json 是直接当成 model 返回时, 非常容易复现
from umi.
在你的 demo 复现里,这段代码:
let a = Object.create({}, { a: Math.random() });
let b = Object.create({}, { b: Math.random() });
a.b = b;
在浏览器控制台运行了一下,会直接报错的,这是一段错误的代码。
只要接口返回的 json 是直接当成 model 返回时, 非常容易复现
如有问题,需要给一个最小复现。
from umi.
不好意思, 搞错了. 已更新例子
问题应该就 useModel() 方法的第二个参数. 在第二次渲染的时候, 会对新旧 2 个对象调用下面这个 isEqual
方法, 而 isEqual
又会调用 valueOf
方法导致报错.
umi/packages/plugins/libs/model.tsx
Line 162 in 9594ec2
from umi.
你新给的 codesandbox 例子里,这段代码:
const { a } = useModel('index', ({ a }) => {
a;
});
是没有返回值的,在 js 里返回值必须使用 return { a }
,如果要省略 return ,对于 object 类型的需要添加括号,比如 () => ({ a })
/ () => 1
/ () => []
,更多方式请自行查找学习。
如果改成 return { a }
就可以正常运行了。
至于你提到的 valueOf
问题:
在各种 react 全局状态管理方案里,use model 这个方案是属于使用原生 context 的原生方案,比较轻量,但 context 中的数据只要有任何值更新了,整个 context 下面的内容都会重渲染,这里 use model 在每次数据更新时使用 equal 对比方法来避免一部分重渲染的问题,所以就需要你的对象拥有能对比值的实现。
Object.create
是创建纯对象的方法,不是一般的对象,创建一个对象应该使用 {}
,纯对象一般用于需要自行实现原生方法避免冲突(如 toString
)或特殊不需要继承方法的安全场景,99% 的情况你并不需要纯对象,所以当你有需求需要使用纯对象时,应该自行实现各种你需要的继承方法,如果你需要使用 use model ,就需要最少实现 valueOf
,但我并不确定在 react 、use model 、其他的三方库代码中是否还会使用其他继承方法,所以如果你需要使用纯对象,为了避免在应用中传递、使用时出现问题,所有可能需要的方法都应该自己实现。
from umi.
Related Issues (20)
- umi/examples/mfsu-independent不能启动 HOT 2
- [Bug] antd 5 umi4。通过app.tsx里面 rootContainer配置antd全局国际化,不生效 HOT 6
- [Bug] umi 4 使用 MF v2 插件问题 HOT 6
- [Bug] Linux环境打包后,chunk中出现React,导致报错:ReferenceError: React is not defined HOT 3
- 1.import { history, request } from 'umi'; HOT 3
- umi4.x 配置base之后,history.push 跳转相对路径不生效 HOT 2
- 从v3升级到v4 No matching export in "src/.umi/exports.ts" for import "useModel" HOT 4
- [Feature Request] biomejs support HOT 1
- [Bug] openapi生成的services中的数据类型 HOT 1
- [Bug] useModel 怎么关闭隐式调用 HOT 2
- [Bug] useModel 怎么关闭隐式调用 HOT 2
- 可以打包两个html文件html文件对应的路由不一样在哪配置呢? HOT 2
- [Bug] model 插件和 antd 改变主题互相冲突 HOT 2
- useModel在login之前就执行了,导致没有拿到models的结果,登录后也不会再次执行 HOT 1
- [Bug] Proxy can't support WebSocket and make umi crashed HOT 2
- [Bug] umijs4版本左侧菜单折叠后再打开 submenu动画有残影 HOT 1
- umijs 怎么打包配置多个页面呢? HOT 1
- [Bug] umi^4.2.5怎么把id="app" 自定义其他名称,比如叫id="app1" HOT 2
- [Feature] 优先使用用户安装的 `babel-plugin-react-compiler`
- [Task] PR #12398 代码修复 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umi.