import {createSlice} from "@reduxjs/toolkit"; import {HYDRATE} from "next-redux-wrapper"; import {AppState} from "./store"; export interface BlogSearchState { results: object[]; } // Initial state const initialState: BlogSearchState = { results: [], }; // Actual Slice // @ts-ignore export const blogSearchSlice = createSlice({ name: "blogSearch", initialState, reducers: { // Action to set the authentication status setBlogSearchState(state, action) { // @ts-ignore state.results = action.payload; }, // Special reducer for hydrating the state. Special case for next-redux-wrapper extraReducers: { // @ts-ignore [HYDRATE]: (state, action) => { return { ...state, // @ts-ignore ...action.payload.blogSearch, }; }, }, }, }); export const {setBlogSearchState} = blogSearchSlice.actions; export const selectBlogSearchState = (state: AppState) => state.blogSearch; export default blogSearchSlice.reducer;