taro icon indicating copy to clipboard operation
taro copied to clipboard

更新了 0.0.64 版本,redux 使用上出了点问题

Open Dithub2016 opened this issue 8 years ago • 4 comments

@connect(
  () => {},
  dispatch => ({
    asyncDeleteAddress: id => dispatch(asyncDeleteAddress(id)),
    asyncSetDefaultAddress: id => dispatch(asyncSetDefaultAddress(id)),
  })
)

mapStateToProps 传了个空函数会报错, 如下: TypeError: Cannot convert undefined or null to object at n.keys () at Connect.stateListener (index.js:136) at dispatch (redux.js:227) at redux-logger.js:1 at index.js:14 at dispatch (redux.js:569) at action.js:54 at

image 里面的 newMapState 是 undefined, 但这样写在 0.0.63 版本是好的, 现在把 mapStateToProps 参数改成 () => ({}),就好了。 这算是一个 bug 吗?

Dithub2016 avatar Jul 03 '18 01:07 Dithub2016

() => {} 这个函数出来的确是一个 undefined, 他就相当于你写 function () {}。

() => ({})才是真正的返回一个空对象。

yuche avatar Jul 04 '18 03:07 yuche

是啊,taro 的版本一升就改了点细节,然后这个参数不打算支持传 undefined 的情况吗

Dithub2016 avatar Jul 04 '18 06:07 Dithub2016

请问在你升级 64 之前用的是哪个版本?

yuche avatar Jul 04 '18 06:07 yuche

翻 git 记录,到 63 版本之前是以 () => {}, 留空的, 但刚刚回退到 63,64,即使是 65 版本,这个写法都是可以运行, 没有复现TypeError: Cannot convert undefined or null to object这个问题

Dithub2016 avatar Jul 04 '18 08:07 Dithub2016