function MoviePage(){
const [movies, setMovies] = useState([]);
const [searchValue, setsearchValue] = useEffect('');
const getMovieRequest = async (searchValue) => {
const url = `http://www.omdbapi.com/?s=${searchValue}&apikey=d03f9066`;
const response = await fetch(url);
const responseJson = await response.json();
if (responseJson.Search){
setMovies(responseJson.Search);
}
};
useEffect(() => {
getMovieRequest(searchValue);
}, [searchValue]);
输出Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
WARNING in [eslint]
srcpagesMovie.js
Line 11:43: React Hook useEffect received a function whose dependencies are unknown. Pass an inline function instead react-hooks/exhaustive-deps
webpack compiled with 1 warning
错误被抛出
const [searchValue, setsearchValue] = useEffect('');
我想你希望它是:
const [searchValue, setsearchValue] = useState('');