Skip to content

Instantly share code, notes, and snippets.

@happyharis
Created July 21, 2022 11:36
Show Gist options
  • Save happyharis/861f592512c63a0fb2fad815d55148ab to your computer and use it in GitHub Desktop.
Save happyharis/861f592512c63a0fb2fad815d55148ab to your computer and use it in GitHub Desktop.
PCMOB 6 Setup: store and reducer
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;
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