Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using Redux and React for my project. I have some Routes in App.js. I also use the connect function in react-redux in my project. To prevent update blocking issue, I usually wrapped my component in this way

withRouter(connect(mapStateToProps, mapDispatchToProps)(App)),

However, If I changed order of withRouter and connect it doesn't work:

connect(mapStateToProps, mapDispatchToProps)(withRouter(App))

I have console.log the props in App.js. It already receives location and history props. I am figuring out the theory behind why the order does matter ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use it with the method compose from redux library.

export default compose(
  withRouter,
  connect(mapStateToProps, mapDispatchToProps)
)(App);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...