Created
July 21, 2022 11:36
-
-
Save happyharis/861f592512c63a0fb2fad815d55148ab to your computer and use it in GitHub Desktop.
PCMOB 6 Setup: store and reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createSlice } from "@reduxjs/toolkit"; | |
const initialState = [ | |
{ id: "1", title: "First Post!", content: "Hello!" }, | |
{ id: "2", title: "Second Post", content: "More text" }, | |
]; | |
const notesSlice = createSlice({ | |
name: "notes", | |
initialState, | |
reducers: { | |
noteAdded(state, action) { | |
state.push(action.payload); | |
}, | |
}, | |
}); | |
export const { noteAdded } = notesSlice.actions; | |
export default notesSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { configureStore } from "@reduxjs/toolkit"; | |
import notesReducer from "./features/notesSlice"; | |
export default configureStore({ | |
reducer: { | |
notes: notesReducer, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment