Reshort - write less in your action creators!
Intro
Hi, everyone! I developed this simple little lib (my first lib!) to help me reduce some repetition in my action creators. I have some ideas of new implementations and I just want to see if anyone is interested in this at all or find this project interesting and useful. If you have any constructive critiques I would be very pleased to hear it. If you have some interest in the project and can help, it would be awesome!
The problem:
Let's say that I want to fetch a list of books. Using redux, I have to create three actions creators:
- the first one is the "REQUEST";
- the second one is the "SUCCESS";
- the third one is the "FAIL".
Now let's say that I want to fetch a list of authors. Or a list of users. Or a list of bookmarks... This pattern of REQUEST-SUCCESS-FAIL can become very repetitive and verbose.
The solution
Using reshort
you can create one "complete action creator" using one line, instead of three. Like so:
import reshort from "reshort";
const productsActions = reshort("Products");
productsActions("request")
// {
// type: "GET_PRODUCTS"
// }
productsActions("success", {test: 123})
// {
// type: "GET_PRODUCTS_SUCCESSFUL",
// payload: { test: 123 }
// }
productsActions("fail", {test: "error"})
// {
// type: "GET_PRODUCTS_FAILURE",
// payload: { test: "error" }
// }
Top comments (1)
I've found that this whole time the link was incorrect.
Now it is correct!