Web Browser Methods
NEAR Components have access to classic web methods that enable them to:
- Fetch data from external sources.
- Cache values to avoid redundant computations.
- Use LocalStorage to store data in the web browser.
- Access to the Clipboard.
Fetch
fetch allows to fetch data from the URL. It acts like a hook. It's a wrapper around the fetch function from the browser behind the caching layer.
The possible returned values are:
- If the data is not cached, it returns
nulland fetches the data in the background. - If the data is cached, it returns the cached value and then revalidates it.
Loading...
Async Version
asyncFetch is the async version of fetch, meaning that it returns a promise instead of a value.
Loading...
提示
In contrast with fetch, asyncFetch does not cache the resulting value, so it should only be used within a function to avoid frequent requests on every render.