Skip to content

Commit

Permalink
added empty string case Relates #11
Browse files Browse the repository at this point in the history
  • Loading branch information
minju25kim committed Jun 10, 2022
1 parent 980f907 commit f0c863a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import React from "react";
function Search({ search }) {
const [movie, setMovie] = React.useState([]);

const URL = "https://api.themoviedb.org/3/search/movie";
const api_key = import.meta.env.VITE_TMDB_API_KEY;
const searchURL = `${URL}?api_key=${api_key}&query=${search}`;

React.useEffect(() => {
const URL = "https://api.themoviedb.org/3/search/movie";
const api_key = import.meta.env.VITE_TMDB_API_KEY;
let searchURL = `${URL}?api_key=${api_key}&query=${search}`;
fetch(searchURL)
.then((response) => response.json())
.then((data) => setMovie(data));
}, [search]);

if (search === false) {
if (search === "") {
return <div>empty string is unacceptable.</div>;
} else if (search === false) {
return <div>Search movie title : )</div>;
} else {
const genres = movie.results[0].genre_ids;
Expand Down

0 comments on commit f0c863a

Please sign in to comment.