Код: Выделить всё
{$$typeof: Symbol(react.element), type: 'p', key: null, ref: null, props: {…}, …}
обратите внимание: запрос настроен на отправку неправильных входных данных, чтобы получить ошибку
Код: Выделить всё
export default function App() {
const [movies, setMovies] = useState([]);
const [watched, setWatched] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState("");
const query = "hgjhgh";
useEffect(function () {
async function fetchMovies() {
try {
setIsLoading(true);
const res = await fetch(
http://www.omdbapi.com/?i=tt3896198&apikey=${KEY}&s=${query}
);
if (!res.ok) {
throw new Error("Something went wrong with fetching movies");
}
const data = await res.json();
if (data.Response === "False") {
throw new Error("Movie not found");
}
setMovies(data.Search);
} catch (err) {
console.log(err);
setError(err.message);
} finally {
setIsLoading(false);
}
}
fetchMovies();
}, []);
return (
{isLoading && }
{!isLoading && !error && }
{error && }
{/* */}
);
}
function Loader() {
return
Loading...
;
}
function Error({ error }) {
return
{error}
;
}
...remaining code
это простое приложение для рендеринга фильмов из omdb. Я только начал это создавать.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ct-element