Comments (4)
看起来像是 immer 的报错,什么场景出现的?
from stook.
看起来像是 immer 的报错,什么场景出现的?
- 定义了一个 config
const [dataSourceConfig] = useStore('dataSourceConfig', res);
config 里是一个对象变量
对外暴露的修改方式 我是直接返回对象的
handleTableDataSourceConfig: (value) => {
mutate('dataSourceConfig', (state: ProtableDataSourceState) => {
return { ...state, ...value };
});
},
源码在这:https://github.com/arvinxx/components-editor-test/blob/master/src/models/dataSource.ts#L90
这个项目是一个 ProTable 编辑器,之前在业务里用了 dva。近期准备抽出来组件化并开源,所以需要脱离 dva。
在找数据流解决方案的时候看到你的项目来着,感觉用起来还可以,赞一下。
from stook.
不清楚value是什么类型,如果是一个复杂类型是不是可能有什么意外,你先改成这样试试?
handleTableDataSourceConfig: (value) => {
const state = getState('dataSourceConfig')
mutate('dataSourceConfig', { ...state, ...value })
},
from stook.
mutate 的核心代码如下,不知道你这个在哪步报错了:
private getNextState(value: any): any {
let nextState: any
// not function
if (typeof value !== 'function') return value
// can not use immer
if (typeof this.state !== 'object') return value(this.state)
let useImmer = true
const immerState = produce(this.state, draft => {
const fnValue = value(draft)
// use function return value
if (fnValue && typeof fnValue === 'object') {
nextState = fnValue
useImmer = false
}
})
if (useImmer) {
nextState = immerState
}
return nextState
}
from stook.
Related Issues (9)
- 初始值依赖组件的渲染顺序?? HOT 1
- 如何取消一个请求。 HOT 2
- useFetch 与useEffect 是否不同 HOT 1
- 可以在React组件外部订阅状态更新吗? HOT 1
- 支持class component HOT 2
- 针对 useStore,能否加一个泛型来约束 key 值 HOT 2
- key 越来越多,Storage 这个对象会越来越大,会不会有性能问题? HOT 2
- useStore能否支持useSelector 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 stook.