Skip to content

Commit

Permalink
fix:fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ab3MN committed Nov 15, 2024
1 parent 905c871 commit fa4c274
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/hooks/useLocaLStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ interface IUseLocalStorage {

const useLocaLStorage = (key: string): IUseLocalStorage => {
const setItem = (value: unknown): void => {
typeof value === 'string'
? localStorage.setItem(key, value)
: localStorage.setItem(key, JSON.stringify(value));
if (typeof value === 'string') {
localStorage.setItem(key, value);
} else {
localStorage.setItem(key, JSON.stringify(value));
}
};

const getItem = (): unknown => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelectedTodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useSelectedTodo = () => {
setSelectedTodo(null);
}
},
[setSelectedTodo],
[selectedTodo],
);

useLayoutEffect(() => {
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useTodos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect, useState } from 'react';
import { useCallback, useLayoutEffect, useState } from 'react';
import { Todo } from '../types/Todo';
import {
getCompletedTodos,
Expand All @@ -13,11 +13,12 @@ export const useTodos = () => {
const [todos, setTodos] = useState<Todo[]>([]);
const { getItem, setItem } = useLocaLStorage('todos');

const fetchTodos = () => {
const fetchTodos = useCallback(() => {
const localTodos = <Todo[]>getItem();

setTodos(localTodos ? localTodos : []);
};
}, []);

Check warning on line 20 in src/hooks/useTodos.ts

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

React Hook useCallback has a missing dependency: 'getItem'. Either include it or remove the dependency array

const addTodo = (title: string): Todo | void => {
const todo = {
title,
Expand Down Expand Up @@ -79,7 +80,7 @@ export const useTodos = () => {

useLayoutEffect(() => {
fetchTodos();
}, []);
}, [fetchTodos]);

return {
todos,
Expand Down

0 comments on commit fa4c274

Please sign in to comment.