Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to call the API when the search value changes

import React, { useState, useEffect } from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
import MovieList from './components/MovieList';
import MovieListHeading from './components/MovieListHeading';
import SearchBox from './components/SearchBox';

const App = () => {
	const [movies, setMovies] = useState([]);
	const [searchValue, setSearchValue] = useState('');

	const getMovieRequest = async (searchValue) => {
		const url = `http://www.omdbapi.com/?s=${searchValue}&apikey=263d22d8`;

		const response = await fetch(url);
		const responseJson = await response.json();

		if (responseJson.Search) {
			setMovies(responseJson.Search);
		}
	};

	useEffect(() => {
		getMovieRequest(searchValue);
	}, [searchValue]);

	return (
		<div className='container-fluid movie-app'>
			<div className='row d-flex align-items-center mt-4 mb-4'>
				<MovieListHeading heading='Movies' />
				<SearchBox searchValue={searchValue} setSearchValue={setSearchValue} />
			</div>
			<div className='row'>
				<MovieList movies={movies} />
			</div>
		</div>
	);
};

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: add multiple phone using js 
Javascript :: .every() Accepts a test function and returns a boolean if all the elements of the array pass the test. 
Javascript :: unicons add all icons 
Javascript :: Who likes it 
Javascript :: permissions in chrome extension javascript 
Javascript :: axios imgbb 
Javascript :: white for file loaded 
Javascript :: Move capital letters to the beginning 
Javascript :: JavaScript date format 2 
Javascript :: TypeError: (0 , import_dev.useParams) is not a function remix 
Javascript :: HDEL in redis 
Javascript :: Adding A Property To BuiltIn Class In Javascript 
Javascript :: event.target javascript 
Javascript :: javascript every nested array 
Javascript :: event listeners 
Javascript :: sveltekit new app 
Javascript :: check if is array javascript 
Javascript :: hide and show div using javascript with example 
Javascript :: javascript find json value 
Javascript :: take off element form end of array 
Javascript :: postgres json 
Javascript :: js random seed 
Javascript :: function with .map javascript 
Javascript :: how to check if a user is logged in javascript 
Javascript :: where from terminal colors come 
Javascript :: parse json java 
Javascript :: loop for of 
Javascript :: building an array of a numbers javascript 
Javascript :: sort array with negative numbers 
Javascript :: vue js tutorial csv import 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =