How to use useStore, useSelector, useDispatch hook?

心已入冬 提交于 2020-04-30 05:47:09

问题


New hooks have been released with Redux version 7.1.0. I don't understand how to use these hooks in practice. Can someone give an example of how to use these hooks?


回答1:


Please see sample.

  • useSelector is like mapStateToProps, you select properties from store and component is updated when store is changed

  • useDispatch is just returning dispatch. It like calling connect() with empty second argument.

  • useStore is used to retrieve store. But such store access can only be used for store manipulation, like reducer replacement. When store is changed, component which access store this way is not updated.

    Click Check2 button in example above and check2 is not checged untill you click 'update me' button



来源:https://stackoverflow.com/questions/57197859/how-to-use-usestore-useselector-usedispatch-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!