taro icon indicating copy to clipboard operation
taro copied to clipboard

@tarojs/redux 的 connect 函数,mapStateToProps 的执行问题

Open Dithub2016 opened this issue 8 years ago • 0 comments

问题描述 在一个自定义组件当中使用了 connect, mapStateToProps 函数 写了 () => {}, 在当前页面 A 渲染该组件时正常运行,但跳转页面后 (到 AddressList),报错

复现步骤

// AddressWithOrder.js 组件,只用在 A 页面
@connect(
  () => {console.log(111)}, // 111 在当前页面正常输出,跳转到 AddressList 页面后也输出一次,接着报错
  () => ({})
)

// AddressList 页面,没有 AddressWithOrder.js 组件
@connect(
  ({address}) => ({address}),
  dispatch => ({
    // 两个 函数都会修改 address 数据
    getAddressList: () => dispatch(asyncGetAddressList()),  // type: 'SET_ADDRESS_LIST'
    selectAddress: id => dispatch(selectAddress(id)),
  })
)

期望行为 未知

报错信息 跳转后的输出

111
redux-logger.js:1  action SET_ADDRESS_LIST @ 11:29:51.818
redux-logger.js:1  prev state {address: {…}}
redux-logger.js:1  action     {type: "SET_ADDRESS_LIST", addressList: Array(4)}
redux-logger.js:1  error      TypeError: Cannot convert undefined or null to object
    at n.keys (<anonymous>)
    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:65
    at <anonymous>
redux-logger.js:1  next state {address: {…}}

具体为 image

系统信息

  • 操作系统: win7
  • Taro 版本 0.0.67
  • Node.js 版本 v8.11.2

补充信息 这是编译为 小程序 的运行情况,h5 没测试 mapStateToProps 返回 {} ,即 () => ({}) 什么问题也没有 复现了这个 #249 的问题

Dithub2016 avatar Jul 05 '18 03:07 Dithub2016