Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaks with useState/useEffect #63

Open
vogler opened this issue Nov 16, 2022 · 0 comments
Open

breaks with useState/useEffect #63

vogler opened this issue Nov 16, 2022 · 0 comments

Comments

@vogler
Copy link

vogler commented Nov 16, 2022

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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant