Skip to content

jessewarren-aa/redux-slicer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stargazers Issues


Logo

Redux Slicer

Generate redux slices, reducers, selectors, and thunks quickly
View Demo (coming soon) · Report Bug

Prerequisites

npm install npm@latest -g

Installation

npm install redux-slicer
import generateSlice from "redux-slicer"

(back to top)

Usage

  • Slice creation
import generateSlice from "redux-slicer"

export const messagesSlice = generateSlice({
  name: "messages",
  secure: true, // optional, defaults to true
  url: "yourwebsite.com" // optional, defaults to localhost:5000
})

// import { configureStore } from '@reduxjs/toolkit'
export default configureStore({
  reducer: {
    messages: messagesSlice.reducer,
  },
})
  • generateSlice object
newSlice = {
  reducer: createSliceResult, // thanks Redux Toolkit!
  selectors: {
    selectErrors: [Function],
    selectAll: [Function],
  },
  thunks: {
    // all references to headers are optional
    getOneMessages: [Function], // thunkProps = { id, headers }
    getAllMessages: [Function], // thunkProps = { headers }
    // backend success should return { data: [...] }
    createMessages: [Function], // thunkProps = { body, headers }
    updateMessages: [Function], // thunkProps = { body: { ..., id }, headers }
    destroyMessages: [Function] // thunkProps = { id, headers }
  }
}

API Assumptions

  1. if backend failure, returns { errors: [...] }
  2. if backend success, returns { data }

(back to top)

Acknowledgments

(back to top)

About

Generate redux slices, reducers, selectors, and thunks quickly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published