Giter Club home page Giter Club logo

deanilvincent / react.js-reduxtoolkit-typescript-crud-sample Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 7.0 1.09 MB

This repository provides a basic but dynamic demo & reference for React.JS with Redux Toolkit that performs CRUD (Create, Read, Update & Delete) operations. The project is also using typescript as part of the react template.

Home Page: https://reactjs-ts-crud-with-reduxtoolkit.netlify.app/

License: MIT License

HTML 10.12% CSS 0.24% TypeScript 89.65%
redux-toolkit reactjs crud-application

react.js-reduxtoolkit-typescript-crud-sample's Introduction

React.JS Typescript with ReduxToolkit CRUD Sample

Overview

This repository provides a basic but dynamic demo & reference for React.JS with Redux Toolkit that performs CRUD (Create, Read, Update & Delete) operations. The project is also using typescript as part of the react template.

Demo

Demo

(Note: Download Redux Dev Tools chrome extension for better visibility of your store: Redux DevTools)

Redux Toolkit:

  • Simple - Provides good defaults for store setup out of the box, and includes the most commonly used Redux addons built-in.
  • Opinionated - Provides good defaults for store setup out of the box, and includes the most commonly used Redux addons built-in.
  • Powerful - Takes inspiration from libraries like Immer and Autodux to let you write "mutative" immutable update logic, and even create entire "slices" of state automatically.
  • Effective - Lets you focus on the core logic your app needs, so you can do more work with less code.

You can read more from the official documentation: https://redux-toolkit.js.org/

Getting Started

  1. Restore the package by running the npm i inside the directory where package.json is stored.
  2. Connect to the web api endpoint. You can use the deployed endpoint or use your local. This can be modified inside the api.ts
  3. Run the app using: npm run start
  4. To build: npm run build

Additional Info

  • store.ts - This is where we configure and register our reducers.
  • index.tsx - After creating the store file, we configured the index.tsx to use the <Provider store={store}>
  • components folder - Where we stored our reusable components like Button, Input & Checkbox.
  • features folder - Where we add our business modules. In our example, it's the Employee folder.
  • employeeSlice.ts - This is where we create a slice with its reducers. You can create multiple slices depending on your requirements and features.
export const employeeSlice = createSlice({
    name: "employee",
    initialState: {
        list: {
            isLoading: false,
            status: "",
            values: []
        },
        save: {
            isSaving: false,
            isDeleting: false
        }
    },
    reducers: {
        clearSuccessMessage: (state, payload) => {
            // TODO: Update state to clear success message
        }
    },
    extraReducers: {
        [getEmployees.pending.type]: (state, action) => {
            state.list.status = "pending"
            state.list.isLoading = true
        },
        [getEmployees.fulfilled.type]: (state, { payload }) => {
            state.list.status = "success"
            state.list.values = payload
            state.list.isLoading = false
        },
        [getEmployees.rejected.type]: (state, action) => {
            state.list.status = "failed"
            state.list.isLoading = false
        }
    }
    ...
})

Here's the brief details for the key declared above.

Key Description
name Name of the reducer
initialState Where we declare the initial state of this slice.
reducers We put non-async reducers here.
extraReducers For async reducers like calling a web api endpoints or working with external resources.

Other Packages Used:

Contribute

Feel free to share, or even clone or fork this project: https://github.com/deanilvincent/React.JS-ReduxToolkit-Typescript-CRUD-Sample.git

Contribution & pull request is welcome!

I'll be glad if you give this project a ★ on Github :))

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

react.js-reduxtoolkit-typescript-crud-sample's People

Contributors

deanilvincent avatar

Stargazers

 avatar Masoud avatar souvik dutta avatar Omar Khouya avatar  avatar Fernando Constantino Ngana avatar Kaushik Ravikumar avatar Ishwar Shelke avatar Vu Thi Hong Oanh avatar Debashish Dutta avatar MD RAKIBUL HASAN avatar nguyentranthevu avatar Muhammed Shahir M S avatar  avatar  avatar  avatar  avatar Jerem avatar  avatar Raghu Erukulapati avatar  avatar Thésée (Thiseas) Kambas avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.