breaks with `useState`/`useEffect`
vogler opened this issue · 0 comments
vogler commented
data
is loaded fine (1. log), but once I call useState
or useEffect
, the code after (2. log) is no longer executed.
Not sure what's going on. No exception thrown. Works fine with plain fetch
.
Did I miss something?
import useFetch from 'react-fetch-hook'; // 1.9.5
const UserTable = () => {
const [users, setUsers] = useState([]);
const { isLoading, data, error } = useFetch('/admin/users');
console.log('data', isLoading, data, error);
if (isLoading || !data) return 'Loading...';
if (error) return 'An error has occurred: ' + error.message;
// setUsers([]); // if called, the following code is dead
// useEffect(() => { console.log('data changed') }, [data]); // same with this
console.log('data2', data);
};