Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Hook useEffect received a function whose dependencies are unknown. Pass an inline function instead 1 warning

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]);

output

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

WARNING in [eslint]
src\pages\Movie.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

>Solution :

The error is thrown in

const [searchValue, setsearchValue] = useEffect('');

I think you wanted it to be:

const [searchValue, setsearchValue] = useState('');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading