Skip to content

Conversation

@Sam2303
Copy link
Contributor

@Sam2303 Sam2303 commented May 18, 2025

Description

add an option to the useFetchye called forceInitialFetch to allow the consumer to ignore the cached value.

Motivation and Context

I have run into multiple occasions where I want to use this hook but sometimes want to ignore the cached value from a previous request.
flow:

  1. user goes to a list page where a useFetchye hook is present and gets the initial data from the server
  2. User goes to a new page to add a new object which is sent to the server to be saved, and the user is then auto-redirected to the list page from step 1.
  3. they can not see their newly created object as the api call is not happening and its taking the previously fetched data from the cache.

without some code like:

() => {
  const queryParam = getQueryParam("from-create-form");
  const fetchyeRes = useFetchye("myData.com", { defer: queryParam === "true" });
  useEffect(() => {
    if (queryParam === "true") {
       fetchyeRes.run();
    }
  }, [queryParam ]);

  return null;
}

instead we could just do something like

() => {
  const queryParam = getQueryParam("from-create-form");
  const fetchyeRes = useFetchye("myData.com", { forceInitialFetch: queryParam === "true" });
  
  return null;
}

it completely negates the need for the useEffect

How Has This Been Tested?

unit test added

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My changes are in sync with the code style of this project.
  • There aren't any other open Pull Requests for the same issue/update.
  • These changes should be applied to a maintenance branch.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using Fetchye?

no breaking change but the new option to forceInitialFetch data

@Sam2303 Sam2303 requested review from a team as code owners May 18, 2025 18:01
@CLAassistant
Copy link

CLAassistant commented May 18, 2025

CLA assistant check
All committers have signed the CLA.

@Matthew-Mallimo
Copy link
Member

@Sam2303 change makes sense, but I worry the communication here is confusing. the forceFetch field will always be true, but wont always fetch (it only will fetch if its the first render). wondering if there is a better way to communicate whats happening.

@Sam2303
Copy link
Contributor Author

Sam2303 commented Jun 9, 2025

@Sam2303 change makes sense, but I worry the communication here is confusing. the forceFetch field will always be true, but wont always fetch (it only will fetch if its the first render). wondering if there is a better way to communicate whats happening.

@Matthew-Mallimo that makes sense! Wonder if something like forceInitialFetch makes more sense? Or do I change direction completely and make the option more along the lines of refreshCache

@Sam2303 Sam2303 changed the title Feat/useFetchye-force-fetch Feat/useFetchye-force-initial-fetch Jun 10, 2025
@Sam2303
Copy link
Contributor Author

Sam2303 commented Jun 10, 2025

@Sam2303 change makes sense, but I worry the communication here is confusing. the forceFetch field will always be true, but wont always fetch (it only will fetch if its the first render). wondering if there is a better way to communicate whats happening.

I took some time to think about it, and to me forceInitialFetch makes the most sense to me, I have updated this PR to match that. let me know what you think

@laurenHorton laurenHorton merged commit 1a77651 into americanexpress:main Jul 15, 2025
5 of 6 checks passed
Matthew-Mallimo pushed a commit that referenced this pull request Jul 15, 2025
* feat(useFetchye): forceFetch

* feat(readme): forceFetch

* feat(option): forceInitialFetch
Matthew-Mallimo pushed a commit that referenced this pull request Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants