Skip to content

Commit

Permalink
Summary
Browse files Browse the repository at this point in the history
  • Loading branch information
EuJinnLucaShow committed Dec 29, 2023
1 parent 76fb7b1 commit 4673824
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/TodoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@ import Pagination from '../utils/Pagination';
const PAGE_SIZE = 5;

const TodoList = () => {
const dispatch = useDispatch();
const todos = useSelector(selectTodo);
const reversedTodos = [...todos].reverse();
const [currentPage, setCurrentPage] = useState(0);
const dispatch = useDispatch();

const paginatedTodos = reversedTodos.slice(
currentPage * PAGE_SIZE,
(currentPage + 1) * PAGE_SIZE,
);

const [items, setItems] = useState([]);

useEffect(() => {
setItems(paginatedTodos);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentPage, todos]);

useEffect(() => {
dispatch(fetchTodos());
}, [dispatch]);

useEffect(() => {
const reversed = [...todos].reverse();
const paginatedTodos = reversed.slice(
currentPage * PAGE_SIZE,
(currentPage + 1) * PAGE_SIZE,
);
setItems(paginatedTodos);
}, [currentPage, todos]);

const handlePageChange = ({ selected }) => {
setCurrentPage(selected);
};
Expand Down
1 change: 1 addition & 0 deletions src/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import todoReducer from './todoSlice';
const persistConfig = {
key: 'root',
storage,
whitelist: ['todos'],
};

const persistedReducer = persistReducer(
Expand Down

0 comments on commit 4673824

Please sign in to comment.