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

@brightleaf/react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brightleaf/react-hooks - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

lib/use-request.js

58

lib/use-get.js

@@ -8,33 +8,45 @@ "use strict";

var _react = require("react");
var _useRequest = _interopRequireDefault(require("./use-request"));
var _reducer = require("./reducer");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const useGet = url => {
const [state, dispatch] = (0, _react.useReducer)(_reducer.reducer, {
const defaultConfig = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrer: 'no-referrer'
};
const useGet = (url = '', config = {
method: 'GET'
}) => {
const {
data,
error,
loading,
makeRequest
} = (0, _useRequest.default)(url, {
data: [],
error: null,
loading: true
loading: false
});
const fullConfig = { ...defaultConfig,
...config
};
const getUrl = async url => {
dispatch({
type: 'get'
});
const resp = await fetch(url);
const data = await resp.json();
dispatch({
type: 'success',
payload: {
data
}
});
const getUrl = async (urlToGet = url) => {
await makeRequest({
method: 'GET',
...fullConfig
}, urlToGet);
};
(0, _react.useEffect)(() => {
if (url) {
getUrl(url);
}
}, [url]);
return { ...state,
return {
data,
error,
loading,
getUrl

@@ -41,0 +53,0 @@ };

@@ -8,8 +8,26 @@ "use strict";

var _react = require("react");
var _useRequest = _interopRequireDefault(require("./use-request"));
var _reducer = require("./reducer");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const usePost = (url = '') => {
const [state, dispatch] = (0, _react.useReducer)(_reducer.reducer, {
const defaultConfig = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrer: 'no-referrer'
};
const usePost = (url = '', config = {
method: 'POST'
}) => {
const {
data,
error,
loading,
makeRequest
} = (0, _useRequest.default)(url, {
data: [],

@@ -19,29 +37,18 @@ error: null,

});
const fullConfig = { ...defaultConfig,
...config
};
const postData = async data => {
dispatch({
type: 'get'
});
const resp = await fetch(url, {
await makeRequest({
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrer: 'no-referrer',
...fullConfig,
body: JSON.stringify(data)
});
const result = await resp.json();
dispatch({
type: 'success',
payload: {
data: result
}
});
};
return { ...state,
return {
data,
error,
loading,
postData

@@ -48,0 +55,0 @@ };

@@ -6,10 +6,28 @@ "use strict";

});
exports.default = exports.usePost = void 0;
exports.default = exports.usePut = void 0;
var _react = require("react");
var _useRequest = _interopRequireDefault(require("./use-request"));
var _reducer = require("./reducer");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const usePost = (url = '') => {
const [state, dispatch] = (0, _react.useReducer)(_reducer.reducer, {
const defaultConfig = {
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrer: 'no-referrer'
};
const usePut = (url = '', config = {
method: 'PUT'
}) => {
const {
data,
error,
loading,
makeRequest
} = (0, _useRequest.default)(url, {
data: [],

@@ -19,29 +37,18 @@ error: null,

});
const fullConfig = { ...defaultConfig,
...config
};
const postData = async data => {
dispatch({
type: 'get'
});
const resp = await fetch(url, {
await makeRequest({
method: 'PUT',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrer: 'no-referrer',
...fullConfig,
body: JSON.stringify(data)
});
const result = await resp.json();
dispatch({
type: 'success',
payload: {
data: result
}
});
};
return { ...state,
return {
data,
error,
loading,
postData

@@ -51,4 +58,4 @@ };

exports.usePost = usePost;
var _default = usePost;
exports.usePut = usePut;
var _default = usePut;
exports.default = _default;
{
"name": "@brightleaf/react-hooks",
"version": "0.8.0",
"version": "0.9.0",
"description": "Useful react hooks",

@@ -5,0 +5,0 @@ "files": [

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