You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 thesubscribedSearches
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.
The text was updated successfully, but these errors were encountered: