I know the conventional way when using hooks is to fetch the data using the useEffect
hook. But why can't I just call axios in the functional component instead of a hook and then set the data.
Basically, I am asking what is wrong with doing this:
const [users, setUsers] = useState(null);
axios.get("some api call")
.then(res => setUsers(res.data))
Here, I do not use useEffect
, what could go wrong?
getUsers
, it'll re-render, triggering another request, triggering another render, ... – Lave