I have the following problem: I am using an Use Effect Hook to update my taskList when I open my WebApp. So I have to lists a list with task which has the attribute recurring tasks (recuringTaskManager.lastWeeklyReset) and a list which can have attributes with recurring and without (taskList). So my goal is to update taskList with the other one when a special condition occur (if differenceInDays....). so I want to delete some tasks in Taskslist therefore the filter function and add them again so that a special attribute can get refreshed. I found out that using hooks in conditions and loops is always bad but I don't know how I could code it without loops and conditions.
Maybe you know
useEffect(() => {
if (!isInitialized) return
if (differenceInDays(new Date("July 28, 2022 00:00:00"), state.recuringTaskManager.lastWeeklyReset) >= 7) {
for (let task of state.recuringTaskManager.recuringTaskListWeekly) {
const {id} = task
setState({...state, taskList: state.taskList.filter((task: Task) => task.id !== id)})
state.recuringTaskManager.recuringTaskListWeekly)
}
setState({...state, taskList: [...state.recuringTaskManager.recuringTaskListWeekly, ...state.taskList]})
}
}, [isInitialized])