Let's say I have a Link that sends me to a page for adding/editing a list entry.
How do I dispatch a Redux action when I click on the Link itself so that I can update the Redux store first, before actually getting redirected to that page.
Eg:
I click on Edit button -> Action is dispatched -> Store updated, {'state': 'edit-mode'} -> Proceed to redirect.
Or do you have another way in mind to accomplish what I'm trying to do?
Maybe when component has mounted, then I will run an action like stateToEdit based on certain conditions? If so, then please show to me your way. Thanks
PS: I'm using only one component for all add/edit/delete. So I'm thinking of a way to render based on the state whether its on edit-mode or delete-mode etc.
Link, you could usebrowserHistory.push(path)with ononClickfunction. Inside this function, dispatch your action, then push to the new location.redux-thunkwhich would probably help organize the code a bit more considering you probably want to perform this "dispatch something, then move to another page" action in various places. Take a peek at Dan's answer here, I'm sure it'll get the gears turning for how you could approach the issue in your context: stackoverflow.com/questions/35493352/…dispatch(increment)calls with a call tobrowserHistory