What i want to do is to show movie not found when there isn't any movie to show. The issue is with the last if conditional which doesn't grab the variable movieNotFound. I don't quite know if it is only beacuse if conditional in jsx doesn't work or is another issue. I also had tried with ternary operator and same thing.
const [isLoading, setisLoading] = useState(true);
const [movieNotFound, setmovieNotFound] = useState(false);
return (
<div>
{isLoading ? (
<div class="spinner-grow" role="status">
<span class="visually-hidden">Loading...</span>
</div>
) : (
<>
if (movieNotFound === true)
{<h1>Movie not found</h1>} else
{
<div>
<h1>{movie.title}</h1>
<h1>{movie.overview}</h1>
</div>
}
</>
)}
</div>
);
}
export default MovieDetails;
movieFoundrather thanmovieNotFound. That way, if you need to do something when the movie is found, you're doingif (movieFound)rather thanif (!movieNotFound). (This is not a hard-and-fast rule, but it's a good guideline.)isLoading=falseandmovieNotFound=truewith ternary operator for your last if, it should work