Loading...

How to Integrate a Custom Reducer into Your Website?

Jayram Prajapati  ·   20 Dec 2022
How to Integrate a Custom Reducer into Your Website?
service-banner

Introduction

You may find the "Custom Reducer Plugin" helpful if you use Redux. This plugin makes it simple to create custom reducers without having to write any custom code. Additionally, it provides an effortless way to manage the state without updating the reducer code manually.

What is a Custom Reducer Plugin?

A Custom Reducer Plugin is used in Redux, a popular state management library in JavaScript. It allows developers to extend or modify the behavior of the Redux store by adding custom logic to the reducer function. This plugin intercepts actions dispatched to the store and provides additional functionality, such as handling specific actions, manipulating the state, or triggering side effects. Custom Reducer Plugins offer a flexible way to customize the behavior of the Redux store and tailor it to specific application requirements.

Installation Guide:

Must check plugin name Spaces

js

import GstReducer from '../store/Gst/Gst.reducer';

const getStaticReducers = (args, callback, instance) => ({
   ...callback(...args),
   GstReducer
});

export default {
   'Store/Index/getReducers': {
       function: getStaticReducers
   }
};

? You can also get references from the GitHub Helpdesk ScandiPWA here.

? In my store> Gst > Gst.action.js

js

export const UPDATE_GST_PRICE = 'UPDATE_GST_PRICE';

/** @namespace Store/Gst/Action/updateGstPrice */
export const updateGstPrice = (gst_charge) => ({
   type: UPDATE_GST_PRICE,
   gst_charge
});

? In my store> Gst > Gst.reducer.js

js

/** @namespace Store/Gst/Reducer/updateGstPrice */
import { UPDATE_GST_PRICE} from './Gst.action';

export const getInitialState = () => ({
     gst_charge : {
           subtotal_excl_cgst_charge:0,
           subtotal_excl_sgst_charge: 0,
           subtotal_excl_igst_charge: 0,
           shipping_excl_cgst_charge: 0,
           shipping_excl_sgst_charge: 0,
           shipping_excl_igst_charge: 0,
           subtotal_incl_cgst_charge: 0,
           subtotal_incl_sgst_charge: 0,
           subtotal_incl_igst_charge: 0,
           shipping_incl_cgst_charge: 0,
           shipping_incl_sgst_charge: 0,
           shipping_incl_igst_charge: 0,      
       }
});


/** @namespace Store/Gst/Reducer/updateGstPrice */

export const GstReducer = (
   state = getInitialState(),
   action
) => {
   const { type } = action;
   switch (type) {
   case UPDATE_GST_PRICE:
       const { gst_charge } = action;
       console.log('GstReducer gst_charge',gst_charge)
       return {
           ...state,
           gst_charge
       };
   default:
       return state;
   }
};

export default GstReducer;

Conclusion: 

  • You can use custom reducer plugins to modify the results of a specific data reduction tool. Plugins must be downloaded from a trusted source and installed to work correctly.
  • The benefits of using a custom reducer plugin include increased flexibility, improved accuracy, and the ability to customize the output.

 

Contact us:+91 8128405131

Email send us at hello@elightwalk.com

Jayram Prajapati
Full Stack Developer

Jayram Prajapati brings expertise and innovation to every project he takes on. His collaborative communication style, coupled with a receptiveness to new ideas, consistently leads to successful project outcomes.

Most Visited Blog

The Power of Traits in PHP: Simplifying Common Property Injection

Discover the power of PHP Traits! Our guide unveils the potential of characteristics by simplifying property injection and providing a simplified solution to typical code difficulties.

After move to another server ScandiPWA theme is not responding.

Are you having problems with the ScandiPWA theme after a server migration? To maintain responsiveness and performance on Magento PWA storefront, use our simple guide to effectively troubleshoot.

How To Create an Extension In PWA studio(Venia)?

Discover the essentials of creating extensions in Venia with our guide. Enhance Magento PWA storefront by developing and implementing extensions that provide capabilities and a personalized user experience.