💡Fanletter 발전시키기
import { createSlice } from "@reduxjs/toolkit";
import fakeData from "fakeData.json";
const initialState = fakeData;
const letterSlice = createSlice({
name: "letter",
initialState,
reducers: {
addLetter: (state, action) => {
const newLetter = action.payload;
return [newLetter, ...state];
},
deleteLetter: (state, action) => {
const letterId = action.payload;
return state.filter((letter) => letter.id !== letterId);
},
editLetter: (state, action) => {
const { id, editingText } = action.payload;
return state.map((letter) => {
if (letter.id === id) {
return { ...letter, content: editingText };
}
return letter;
});
},
},
});
export default letterSlice.reducer;
export const { addLetter, deleteLetter, editLetter } = letterSlice.actions;
import { createSlice } from "@reduxjs/toolkit";
const initialState = "카리나";
const memberSlice = createSlice({
name: "member",
initialState,
reducers: {
setMember: (state, action) => {
const activeMember = action.payload;
return activeMember;
}
}
})
export default memberSlice.reducer
export const {setMember} = memberSlice.actions
import { configureStore } from "@reduxjs/toolkit";
import letters from "../modules/letterSlice";
import member from "../modules/memberSlice";
const store = configureStore({
reducer: {
letters,
member,
},
});
export default store;