【Redux】mergeProps

鬼門connect攻略③ - mergeProps -

connect攻略 part3です

鬼門多きconnectさん↓

connect(

  mapStateToProps

  mapDispatchToProps

  mergeProps

)(myComponent)

今回は mergePropsについて見てきます

 mergePropsで無駄なレンダリングを防げる

‥とのこと https://anect.hatenablog.com/entry/2018/04/18/190841

使いかた

mergeProps(stateProps, dispatchProps, ownProps) {
  return Object.assign({}, ownProps, {
    todos: stateProps.todos[ownProps.userId],
    addTodo: text => dispatchProps.addTodo(ownProps.userId, text)
  })
}

(↑Connect · React Redux より)

  • stateProps : mapStateToPropsの演算結果で生成されたprops

  • dispatchProps : mapDispatchToPropsの演算結果で生成されたprops

Liquidocs