majic / src /redux /reducers /poiReducer.ts
nolual's picture
Upload 55 files
0c20ea8
raw
history blame
813 Bytes
import { createReducer } from "@reduxjs/toolkit";
import { Poi } from "../types/Poi";
import {
fetchPoiRequest,
fetchPoiSuccess,
fetchPoiFailure,
} from "../actions/poiActions";
interface PoiState {
data: Poi[] | null;
loading: boolean;
error: string | null;
}
const initialState: PoiState = {
data: null,
loading: false,
error: null,
};
const poiReducer = createReducer(initialState, (builder) => {
builder
.addCase(fetchPoiRequest, (state) => {
state.loading = true;
state.error = null;
})
.addCase(fetchPoiSuccess, (state, action) => {
state.loading = false;
state.data = action.payload;
})
.addCase(fetchPoiFailure, (state, action) => {
state.loading = false;
state.error = action.payload;
});
});
export default poiReducer;