From cf9d08034ed0656e52ae7fc8b3202bf8d67a5a7f Mon Sep 17 00:00:00 2001 From: TishchenkoSergey Date: Tue, 1 Dec 2020 15:25:58 +0200 Subject: [PATCH] add --- api/api.js | 15 +++++++++++++++ src/App.jsx | 54 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 api/api.js diff --git a/api/api.js b/api/api.js new file mode 100644 index 0000000..2124922 --- /dev/null +++ b/api/api.js @@ -0,0 +1,15 @@ +const BASE_URL = 'http://www.omdbapi.com/?apikey=287c70f0&t='; + +async function request(url) { + const response = await fetch(`${BASE_URL}['${url}']`); + + if (!response.ok) { + throw new Error(`${response.status}`); + } + + return response.json(); +} + +export function getMovies(title) { + return request(title); +} diff --git a/src/App.jsx b/src/App.jsx index f7ee182..58fb234 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,50 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.scss'; -export const App = () => ( -
- React starter pack -
-); +import {getMovies} from '../api/api'; + + +export const App = () => { + const [title, setTitle] = useState(''); + const [movies, setMovies] = useState([]); + const [error, setError] = useState(''); + + const callback = (event) => { + setTitle(event.target.value); + } + + const findMovie = async() => { + try { + const movies = await getMovies(title); + } + catch { + } + } + + return( + <> + + + + + + + ) +};