I am currently making a TodoList app using Recoil and React and I am getting the error:
Line 45:6: React Hook useEffect has missing dependencies: 'setTodoList' and 'todoList'. Either include them or remove the dependency array react-hooks/exhaustive-deps
I believe this is preventing the app from building. It works in development mode.
Please help me fix this!
Here is the concerned file:
export default function Todos() {
// Global State Hooks
const [todoList, setTodoList] = useRecoilState(todoState);
const changing = useRevoilValue(changeState);
const show = useRecoilValue(addState);
const removing = useRecoilValue(removeState);
const priority = useRecoilValue(priorityState);
// **** CODE SEGMENT STARTS HERE ****
useEffect(() => {
if (priority) {
setTodoList(
todoList.slice().sort(function (a, b) {
return a.priority - b.priority; // By priority
})
);
} else {
setTodoList(
todoList.slice().sort(function (a, b) {
return a.title.localeCompare(b.title); // By name
})
);
}
// Watches priority for sortButton, and editing, adding and deleting modes etc.
}, [priority, changing, show, removing]);
// **** CODE SEGMENT ENDS HERE ****
return (
<div className={styles.todos}>
{/* Dynamically render todo items */}
{todoList.map((todo, index) => (
<span key={todo.id} className={styles.todoItem}>
<TodoItem key={index} item={todo} />
</span>
))}
{/* Todo Form only appears in adding mode */}
{show ? <TodoForm /> : null}
</div>
);
}