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

useFetch never fetches if the depends array includes values like an empty string or null #56

Open
hydrogen602 opened this issue Apr 21, 2022 · 0 comments

Comments

@hydrogen602
Copy link

It seems like useFetch never fetches data if the depends is something like [''], but sets isLoading to false immediately, i.e. pretending like it finished loading, but just producing the value undefined. This means that if the value in the depends array is a string that might sometimes be empty, data might just happen to be undefined so any code that expects data to exist if isLoading is false fails.

Full component example:

import useFetch from "react-fetch-hook";


function App() {
  const { isLoading, data } = useFetch("https://api.github.com/", {depends:['']});
  console.log(data);
  return (   
    <p>
      {JSON.stringify(data)}
    </p>
  );
}

export default App;

I'm not sure if this is intended or not, but given that there are situations where depends might include a sometimes empty string, I assume not.

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