Skip to content

First render after key changes has isLoading == false #81

@smackfu

Description

@smackfu

🐞 Bug Report

Describe the bug

On the initial render of a component using fetchye, the returned values are:

{data: undefined, error: undefined, isLoading: true}

Then when the data finishes loading, it changes to:

{data: {…}, error: undefined, isLoading: false}

When the fetchye key (for instance the body of the request) changes, you would expect the state to change back to loading. But instead the first render is this:

{data: undefined, error: undefined, isLoading: false}

This makes it difficult to write any code that is dependent on isLoading to render a loading indicator.

To Reproduce

Example code:

  const [id, setId] = useState(1);
  useEffect(() => {
    setTimeout(() => setId(2), 1000);
  });

  const { data, error, isLoading } = useFetchye(id);
  console.log({ data, error, isLoading });
  return <div>test</div>;

Prints this to console:

{data: undefined, error: undefined, isLoading: true}
{data: undefined, error: undefined, isLoading: true}
{data: {…}, error: undefined, isLoading: false}
{data: undefined, error: undefined, isLoading: false} <====
{data: undefined, error: undefined, isLoading: true}
{data: undefined, error: undefined, isLoading: true}
{data: {…}, error: undefined, isLoading: false}
{data: {…}, error: undefined, isLoading: false}

Expected behavior

isLoading should be true after the key changes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions