Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-fetch-hook

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-fetch-hook - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

4

dist/useFetch.js

@@ -16,2 +16,6 @@ "use strict";

var defaultFormatter = function defaultFormatter(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();

@@ -18,0 +22,0 @@ };

2

package.json
{
"name": "react-fetch-hook",
"version": "1.2.1",
"version": "1.2.2",
"description": "React fetch hook",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -82,2 +82,21 @@ import React from "react";

});
it("error on throw error", async () => {
fetch.mockReject(new Error("fake error message"));
const Component = () => {
const result = useFetch("https://google.com");
return (result.error && result.error.message) || "text";
};
const { container, rerender } = render(<Component />);
await wait(() => {
rerender(<Component />);
expect(fetch.mock.calls.length).toEqual(1);
expect(container).toHaveTextContent("fake error message");
expect(fetch.mock.calls[0][0]).toEqual("https://google.com");
});
});
});

@@ -14,3 +14,8 @@ // @flow

): TUseFetchResult<T> {
const defaultFormatter = response => response.json();
const defaultFormatter = response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
};
const fetchInstance = formatter => (path, options) => {

@@ -17,0 +22,0 @@ return fetch(path, options).then((typeof formatter === "function" && formatter) || defaultFormatter);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc