DEV Community

Orsunmigbare
Orsunmigbare

Posted on

How I automated the React + Redux development process.

I worked on a medium-scale React.js project, which used Redux.js as it's state management tool sometimes last year. I got really bored having to repeat the process of declaring and importing "types" when I need to use a new "type", it got worse when I had to set up the project, repeating the process of creating actions, types, and reducers folders, I got bored. "There has to be an alternative," I thought.

So I embarked on a search on GitHub and NPM for an alternative solution. Although I found options like davezuko/react-redux-starter-kit on Github and @reduxjs/toolkit on NPM, these didn't solve the exact problem I had - repeating the same processes over and over again. So I had to create a solution by myself.

The Problem

Coming from a problem definition to problem solution perspective, I defined my problems as below :

  1. The process of setting up react-redux is boring and repetitive.

  2. Having to create a "type" file and create it's "action" and "reducer" file equivalent is stress.

  3. Having to create and export a new type in a "type file", then importing the type in the use destination drains focus.

  4. Every "reducer" file has the same template, so creating a new reducer file is repetitive in a way (unless doing a copy-and-paste).

  5. Creating a new "reducer" file, importing in the rootReducer file and adding it to the "combineReducer" function is repetitive.

The solution

So I created a shell script with Node.js that handles all these problems.

The script is divided into modules, a "setup" module, and a "watch" module

the "setup" module SETS UP Redux in a basic React.js project by running the command "redux-helper setup" (The Project has to be structured like it was created with Create React App) as seen below.

The "watch" module WATCHES the project after REDUX has been setup and automates basic tasks like :

  1. Synchronizes files across the actions, type and reducer folders respectively (If a type file, a reducer file, or an action file is created, it creates it's equivalent. )

  1. Exports newly created files in the respective index files, and in the case of a reducer file, it imports It in the index file, and add the import to the combine reducer function.

  1. A new redux “type” can be created anywhere from the corresponding action to the corresponding reducer file by using the shortcut !NT “type name” (and the newly created type is exported from the corresponding type file )

  1. A "reducer" and "type" file is created with a basic template,

Phew! something that finally suits my needs..

The code is hosted here on Github if you care 😇.

GitHub logo Orsunmigbare / react-redux-helper

A CLI tool that helps Set-Up redux , and automate repetitive react-redux processes

Kindly share your thoughts and let me know what you think about this project. Happy coding and stay at home guys ☺️.

Top comments (2)

Collapse
 
sebastiandg7 profile image
Sebastián Duque G

Take a look at nx.dev. There @nrwl/react:redux schematic does something similar.

Collapse
 
orsunmigbare profile image
Orsunmigbare • Edited

Thanks sebastian, i'll check it out