npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-toolkit-dynamic-import

v1.0.2

Published

dynamically import/create store structure using the react toolkit

Downloads

11

Readme

redux-toolkit-dynamic-import

Bindings for Redux Toolkit and React/Next JS

Step by Step article on dynamic import (https://medium.com/@ajinkyabhise012/automation-in-redux-toolkit-1cd8aff7ed46)

🚀 Installation 🚀

Installation: yarn i redux-toolkit-dynamic-import or npm i redux-toolkit-dynamic-import

If you want to use dynamic import,you have also installed: npm install @reduxjs/toolkit react-redux axios

👩‍🎓 Why 👩‍🎓

why use redux-toolkit-dynamic-import:

Automatic Reducer Discovery: Saves manual configuration and maintenance effort. Seamless Redux Toolkit Integration: Leverages the familiar APIs and conventions of Redux Toolkit. Enhanced Developer Experience: Offers a more streamlined and enjoyable development process.

Benefits:

Benefits of Using redux-toolkit-dynamic-import:

Improved Performance: By loading reducers only when needed, initial page load times and overall application responsiveness can be significantly boosted. Reduced Bundle Size: By avoiding including unused reducers in the initial bundle, your application's overall size is reduced, leading to faster downloads and better performance on slower networks. Better Code Organization: Separate reducer files promote modularity and maintainability, making your Redux codebase easier to manage and reason about. Enhanced Developer Experience: The automatic reducer discovery and lazy loading mechanism save you time and effort, streamlining the Redux setup process.

👟 Overview & getting started 👟

The following are steps to connect the store and application from the (FrontEnd & BackEnd) as shown below:

Step 1 :

install this cmd: npm i redux-toolkit-dynamic-import & install this cmd: npm install @reduxjs/toolkit react-redux axios

Step 2 :

create a file dyimport.js and add this code :

dyimport.js (shortened):

const yourPackage = require('dynamic-import-redux-toolkit');

const moduleNames = []; add here all model names in lowercase eg : ['product','order','bill']

yourPackage.generateStoreFiles(moduleNames);

step 3 :

go into the package.json file and add this code :

"config-toolkit": "node dyimport.js"

example code :

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "config-toolkit": "node dyimport.js"
  }

step 4 : The next step is to run this cmd for dynamically importing store and models API:

open the terminal and run :

npm run config-toolkit

step 5 :

Integrate the store with front-end using the Provider from react-redux

In Next Js :

Inside the app/layout.js or pages/_app.js folder

"use client";
import "./globals.css";
import { Provider } from 'react-redux';
import store from '../store';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Provider store={store}>
          {children}
        </Provider></body>
    </html>
  );
}

In React Js :

Inside the src/index.js

import React from "react"
import ReactDOM from "react-dom"
import App from "./App"
import { BrowserRouter } from "react-router-dom"
import { Provider } from "react-redux"
import store from "./store"

const app = (
  <Provider store={store}>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </Provider>
)

ReactDOM.render(app, document.getElementById("root"))

step 6 : Add the backend application endpoint to the HTTP server file

httpServer.js

update the URL here httpServer.js is located in the store folder on root location

// Initialize Axios instance with a URL
    const http = axios.create({
      baseURL: 'http://example.com', // Replace with your actual base URL
    });

FINALLY RUN YOU PROJECT AND ENJOY THE DYNAMIC CREATION OF REDUX TOOLKIT STORE.

npm run dev

for how to integrate api from pages please visit my blogs (https://medium.com/@ajinkyabhise012/automation-in-redux-toolkit-1cd8aff7ed46)