Should I use useselector/useDispatch instead of mapStateToProps

后端 未结 5 1386
孤街浪徒
孤街浪徒 2021-02-19 00:07
5条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 00:44

    See EDIT 2 at the end for the final answer

    Since no one knows how to answer, it seems like the best answer is that you should NOT be using useselector when you need information in other places other than the root level of your component. Since you don't know if the component will change in the future, just don't use useselector at all.

    If someone has a better answer than this, I'll change the accepted answer.

    Edit: Some answers were added, but they just emphasize why you shouldn't be using useselector at all, until the day when the rules of hooks will change, and you'll be able to use it in a callback as well. That being said, if you don't want to use it in a callback, it could be a good solution for you.

    EDIT 2: An answer with examples of all that I wanted was added and showed how useSelector and useDispatch are easier to use.

提交回复
热议问题