Я был здесь весь день и не могу понять, что происходит, но кажется, что есть возврат, который возвращает меня к началу !!!! Опять же.import { use } from "react";
import ErrorBoundary from "./error/ErrorBoundary";
function App() {
return (
{/* */}
{/* */}
);
}
function DataDisplay() {
// Usamos 'use' para "esperar" la promesa de fetchData()
console.log("iniciando:");
const data = use(fetchData());
console.log("data:", data);
return (
{data.title}
{data.completed ? "Completado" : "Pendiente"}
);
}
const fetchData = async () => {
try {
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1',{mode: 'cors' });
console.log('Response received:', response);
const data = await response.json();
console.log('Data fetched successfully', data);
return data;//
И это консольный фрагмент; Возврат должен быть выполнен после успешного извлечения данных '. Пожалуйста, дайте мне некоторые подсказки! < /P>
App.tsx:36 Response received: Response {type: 'cors', url: 'https://jsonplaceholder.typicode.com/todos/1', redirected: false, status: 200, ok: true, …}
App.tsx:36 Response received: Response {type: 'cors', url: 'https://jsonplaceholder.typicode.com/todos/1', redirected: false, status: 200, ok: true, …}
App.tsx:38 Data fetched successfully {userId: 1, id: 1, title: 'delectus aut autem', completed: false}
App.tsx:38 Data fetched successfully {userId: 1, id: 1, title: 'delectus aut autem', completed: false}
App.tsx:22 iniciando:
Подробнее здесь: https://stackoverflow.com/questions/797 ... oesnt-work