acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 200 forks source link

What is the best way to remove some data from state when router did changed? #155

Closed CrisLi closed 8 years ago

CrisLi commented 8 years ago

I am looking for a best way to remove some data from state when router changed. I have 3 containers (smart react components), each of them are not related. When I change the router to visit one of these page, I need to remove some data. For instance, the error message is showed in the container-1, then I go to the container-2. After some operations, I go back to container-1, then the message should be dismissed.

I saw a lot of issue/questions have been arised for routerDidChange. But there is not document to show how to use it correctly. In my case, should I use routerDidChange? Do I have to add componentWillUnmount to every containers and dispatch an action to remove the data?

I just want my code more in the Redux way :)

jingzhou123 commented 8 years ago

+1

cateland commented 8 years ago

A middleware should do the trick but i have the fealing, that it would be an overkill.

Scarysize commented 8 years ago

@cateland Yep, I think middleware is the way to go. Hook it in, and listen for the corresponding actions.

@CrisLi Maybe this will help you get started with middleware: https://medium.com/@meagle/understanding-87566abcfb7a#.ljplf19dz

As this is not really router issue, more like a 'reduxy' question, i will close this issue.