Skip to content

Latest commit

 

History

History
97 lines (77 loc) · 2.69 KB

README.md

File metadata and controls

97 lines (77 loc) · 2.69 KB

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)