Where do i put toastr code in a react redux app which uses sagas?

53 Views Asked by At

I have a react redux application that is using sagas to make api calls. I want to use toastr to display error messages. Where do I place the toastr code? In the sagas or in the components?

I can't think of any good reason to put it in the saga. For the common case out there, I image sagas are used to call APIs. An API usually returns a specific error, e.g. 'weight cannot be negative', which is displayed to the user using a Toastr popup, and in addition, the weight text field gets a red background or another UI indication that there's something wrong with it. Why not let the saga set the error state in the reducer, which in turn the component can subscribe to and handle both the error message via Toastr AND the text box field error marking?

The other thing that comes to mind is testing. For unit testing, if you have Toastr code in the sagas, wouldn't you need to additionally mock Toastr?

0

There are 0 best solutions below