async-fetch 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/useAsyncFetch.js +5 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "async-fetch",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Use fetch for requests within React components.",
5
5
  "main": "useAsyncFetch.js",
6
6
  "type": "module",
package/useAsyncFetch.js CHANGED
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
2
2
  import useCache from "./useCache.js";
3
3
  import useInterval from "./useInterval.js";
4
4
 
5
- function useAsyncFetch(requestURL, props = {}) {
5
+ function useAsyncFetch(stringUrl, props = {}) {
6
6
  const {
7
7
  initialPending,
8
8
  initialData,
@@ -44,7 +44,7 @@ function useAsyncFetch(requestURL, props = {}) {
44
44
 
45
45
  useEffect(() => {
46
46
  sendRequest("USE_CACHE");
47
- }, [path, ...deps]);
47
+ }, [stringUrl, ...deps]);
48
48
 
49
49
  useInterval(() => {
50
50
  sendRequest();
@@ -62,15 +62,15 @@ function useAsyncFetch(requestURL, props = {}) {
62
62
  }
63
63
 
64
64
  async function sendRequest(constant) {
65
- if (!requestURL) {
65
+ if (!stringUrl) {
66
66
  throw new Error("URL is required.");
67
67
  }
68
68
 
69
- if (typeof requestURL !== "string") {
69
+ if (typeof stringUrl !== "string") {
70
70
  throw new Error("URL must be of type string.");
71
71
  }
72
72
 
73
- const url = new URL(requestURL);
73
+ const url = new URL(stringUrl, window.location.origin);
74
74
 
75
75
  if (ignoreRequest !== true) {
76
76
  const controller = new AbortController();