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

Communicate API Hooks that the information has been updated #507

Open
tfnribeiro opened this issue Aug 27, 2024 · 1 comment
Open

Communicate API Hooks that the information has been updated #507

tfnribeiro opened this issue Aug 27, 2024 · 1 comment

Comments

@tfnribeiro
Copy link
Contributor

This came up when designing the Searches page, where we are using the hook: useSelectInterests.

In MySearches we are interested to fetch articles for each of the items in the list, but the subscribedSearches that comes from the hook is initialized with an empty string and then updated by the API to either an empty string or a list of different search terms.

In this page, we would like to know if the user doesn't have any searches, or if we are just waiting for the API to return values. This introduces an issue: we don't know if the value we get is set by the API or it's an initalization.

This has been resolved for now, by simply using UseState(), and we then know if the value is undefined, then we know the API has not yet returned - however, is this the way to go?

Personally, initializing UseState() with values should only be done with states that are manipulated without communicating to the API. This is because the states can be changed without delay, and it would always be the result of some user action - while the API calls might be delayed by Network or Server load, and we need to distinguish between having been given an API value or having a "stale" default value.

@igawaclawska
Copy link
Contributor

I'll take a look at it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants