The case this.props.dispatch is empty in React-Redux

 

Why don't I have this.props.dispatch available in my connected component?


The connect() function takes two primary arguments, both optional. 


- The first, mapStateToProps, is a function you provide to pull data from the store when it changes, and pass those values as props to your component. 

- The second, mapDispatchToProps, is a function you provide to make use of the store's dispatch function, usually by creating pre-bound versions of action creators that will automatically dispatch their actions as soon as they are called.


If you do not provide your own mapDispatchToProps function when calling connect(), React Redux will provide a default version, which simply returns the dispatch function as a prop. That means that if you do provide your own function, dispatch is not automatically provided. If you still want it available as a prop, you need to explicitly return it yourself in your mapDispatchToProps implementation.


this.props.dispatch is empty,this.props.dispatch is null, this.props.dispatch is undefined, this.props.dispatch available in my connected component



Reference link: https://redux.js.org/faq/react-redux#why-dont-i-have-thispropsdispatch-available-in-my-connected-component

Nhận xét

Bài đăng phổ biến từ blog này

TypeORM should using repository or query buider ?

Type of children prop in React Typescript

MSAL: Difference between Public Client Application And Confidential Client Application