I'm learning react for past few days and while using useEffect hook i'm getting infite loop over setting my state variable.
Can anyone tell me what's going on and how to overcome this 
Here's my code
import React, { useState, useEffect } from "react";
import axios from "axios";
const TodoEntry = () => {
const [todos, setTodos] = useState('');
useEffect(() => {
axios.get('http://localhost:5000/api/todos')
.then(res => { setTodos(res.data); console.log(todos) })
.catch(err => console.log(err))
},[todos]);
return (
<div>
<h1>Todo App</h1>
</div>
);
};
export default TodoEntry;
useEffect(() => { getTodos(); },[todos]);try this.useEffect(() => getTodos(), []);since you only want to do this once, on mount. If you have a linter which throws an error, then you can wrapgetTodosin auseCallbackto memoize it (not create a new function reference every time we render) and add it back to the dependencies array, or put thegetTodoscode inside theuseEffecthook.useEffecthook's dependency array