Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing routes after successfully saga

I'm trying to figure out what the proper way to go about this is.

Lets say we have a store of items. These items can be edited, deleted and created. When editing or adding an item the route changes to /item/add or /item/edit/{id}.

After an item has been added or edited successfully by saga we want to send them back to the base route. What's the proper way to go about this?

I've seen two ways, one where you inject a history object into a and then include the history object in the saga's as well. Another to keep a "status" ("", "failed", "success") in the item store using in the components and resetting that status when the component unmounts since add and edit both need to use the status.

Which is the proper way to go about this problem though?

like image 792
Justin Masse Avatar asked Jan 30 '23 01:01

Justin Masse


1 Answers

In the past, I've used react-router v3 with react-router-redux integration to dispatch actions that change the route.

React router 4 has a react-router-redux package, which is still in alpha stage. Although it's alpha, this functionality works fine for me, but you should check it for yourself.

In your saga, you can use the put effect to dispatch the action:

import { push } from 'react-router-redux';

yield put(push('/route'));
like image 108
Ori Drori Avatar answered Feb 07 '23 10:02

Ori Drori