Commit 6cdc14d6 authored by Ken's avatar Ken

feat: add reset page for home

parent 4addc5b6
......@@ -17,7 +17,11 @@ export const getNews = createAsyncThunk(
const home = createSlice({
name: "home",
initialState,
reducers: {},
reducers: {
handleResetNews: (state) => {
state.newsData = [];
},
},
extraReducers: (builder) => {
builder.addCase(getNews.fulfilled, (state, action: PayloadAction<any>) => {
const { collection } = action.payload.data;
......@@ -31,5 +35,6 @@ const home = createSlice({
},
});
const { reducer } = home;
const { reducer, actions } = home;
export const { handleResetNews } = actions;
export default reducer;
......@@ -3,7 +3,7 @@ import { homeSelector } from "app/selectors";
import WrapperContainer from "components/WrapperContainer";
import React, { useEffect, useState } from "react";
import Newspaper from "../../components/Newspaper";
import { getNews } from "./homePageSlice";
import { getNews, handleResetNews } from "./homePageSlice";
import { IPagination } from "pages/interface";
import { useInView } from "react-intersection-observer";
import { CircularProgress } from "@mui/material";
......@@ -50,6 +50,11 @@ const HomePage = () => {
}
}, [inView]);
useEffect(() => {
dispatch(handleResetNews());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<main className="homePage">
<WrapperContainer>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment