zustand的useShallow hook到底有什么优势?
zustand的useShallow hook到底有什么优势?使用zustand获取状态大概有三种:const store = useZustand()const {xxx} = useZustand(state => state.xxx)。const {xxx} = useZustand(useShallow(stste => state.xxx))第一种因为会在组件导入所有状态,会导致组件频繁re-render 所以不建议使用。但是zustand文档中建...
1 回答2.5k 阅读✓ 已解决
原因在于:我使用了mobx来作为数据中心的存储
将ObserverArray 转为原生Es6的Array
toJS slice() peek() // 来自mobx官网
注意:
[].push('1') // 得到的不是数组 而是 1
这个时候用concat
// const history = [...this.dataHistory.slice(), ...[{hash: location.hash, data: data}]]
console.log('123', this.dataHistory)
// console.log('456', this.dataHistory.slice())
// console.log('789', this.dataHistory.slice().push({hash: location.hash, data: data})) // !!!得到 1
const history = this.dataHistory.peek().concat([{hash: location.hash, data: data}])