S
S
Scryppi2019-03-05 10:31:26
React
Scryppi, 2019-03-05 10:31:26

How to pass a function to react redux?

I am trying to pass a function to another component via

export default connect(mapStateToProps, mapDispatchToProps)(ProductFooter)

But in ProductFooter, it doesn't accept anything.
mapState, mapDispatch:
const mapDispatchToProps = dispatch => ({
    getReviews: () => dispatch(actions.getReviews.fetch.start(paginationResult)),
    getReviewsFilter: () => dispatch(actions.getReviewsFilter.fetch.start(params[0], params[1])),
});

export default connect(mapStateToProps, mapDispatchToProps)(ProductFooter) // именно этот коннект не работает

product footer:
export const ProductFooter = ({getReviews }) => {
  console.log(getReviews());

  return (
    <div>
    </div>
  )
};

Without this, it works for now through the transfer of props:
<Review item={item} key={item.id} getReviews={props.getReviews} />
   <ReviewContent item={item} getReviews={getReviews}/>
       <ProductFooter item={item} getReviews={getReviews}/>


export const ProductFooter = ({getReviews}) => {
 console.log(getReviews());

  return (
    <div>
    </div>
  )
}

That is, I just pass the function around the tree, instead of passing it directly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question