upd: profile

Deskripsi:
- percobaan fetch profile menggunakan redux
- install package redux

No Issues
This commit is contained in:
amel
2025-04-17 17:29:17 +08:00
parent 043d15bdd9
commit fcad450649
8 changed files with 89 additions and 67 deletions

29
lib/entitiesSlice.ts Normal file
View File

@@ -0,0 +1,29 @@
import { createSlice } from '@reduxjs/toolkit';
const entitiesSlice = createSlice({
name: 'entities',
initialState: {},
reducers: {
setEntities: (state, action) => {
return action.payload;
},
addEntity: (state: any, action: any) => {
state.push(action.payload);
},
updateEntity: (state: any, action) => {
const { id, updatedEntity } = action.payload;
const index = state.findIndex((entity: any) => entity.id === id);
if (index !== -1) {
state[index] = updatedEntity;
}
},
// removeEntity: (state, action) => {
// const idToRemove = action.payload;
// return state.filter((entity: any) => entity.id !== idToRemove);
// },
},
});
export const { setEntities, addEntity, updateEntity } = entitiesSlice.actions;
export default entitiesSlice.reducer;