import { ScrollSpyState, ScrollSpyAction, ScrollSpyActionType } from "./types"; export const scrollSpyInitialState = { index: 0, page: 1, }; export const reducer = ( state: ScrollSpyState = scrollSpyInitialState, action: ScrollSpyAction, ) => { switch (action.type) { case ScrollSpyActionType.UPDATE: return state.index !== action.index ? { ...state, index: action.index, page: action.index + 1, } : state; default: return state; } };