Answer the question
In order to leave comments, you need to log in
How to conditionally render a React component?
The component has a useEffect method in which a request for a back is thrown, three arrays arrive from the back in the form:
{
done: [],
deleted: [],
todo: []
}
if (!allTasksDone) return <>загрузка</>
export const TodoList = ({ update }: TodoListProps) => {
const [data, setData] = useState<any>()
const allTasksDone = data?.allTasks?.todo
useEffect(() => {
const requestBackend = new fetchBackend({ token: localStorage.getItem('token') })
requestBackend.get('/client/getAlltasks').then((response) => response.json()).then((response) => {
setData(response)
})
}, [update])
if (!allTasksDone) return <>загрузка</>
return (
allTasksDone.map((task: any) => {
return <TodoItem taskName={task} done={false} />
})
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question