问题
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.
useSelectoris likemapStateToProps, you select properties from store and component is updated when store is changeduseDispatchis just returningdispatch. It like callingconnect()with empty second argument.useStoreis used to retrievestore. 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