Generate redux slices, reducers, selectors, and thunks quickly
View Demo (coming soon)
·
Report Bug
npm install npm@latest -g
npm install redux-slicer
import generateSlice from "redux-slicer"
- 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 }
}
}
- if backend failure, returns { errors: [...] }
- if backend success, returns { data }