Redux, Do I have to import store in all my containers if I want to have access to the data?

前端 未结 3 1050
忘掉有多难
忘掉有多难 2020-12-12 16:17

Perhaps I am not wrapping my head around redux, but all the examples I\'ve seen don\'t really access state too much between containers and so I haven\'t seen much usage of s

3条回答
  •  执笔经年
    2020-12-12 17:05

    If you use the react-redux package, you'll end up wrapping your components in a Provider with a store prop. This sets up your single store in a React context, which is then accessed from the connect method in child components. The connect method takes two functions (mapStateToProps and mapDispatchToProps), which are your hooks for getting state from the store and dispatching messages.

    Take a look here for more information

提交回复
热议问题