![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@smartrent/use-axios
Advanced tools
Custom React Hooks for Axios.js
Note: Make sure that you have installed the correct version of
react(>= v16.8.0)
andreact-dom(>= v16.8.0)
.
npm install --save @use-hooks/axios
yarn add @use-hooks/axios
/**
* Params
* @param {AxiosInstance} axios - (optional) The custom axios instance
* @param {string} url - The request URL
* @param {('GET'|'POST'|'PUT'|'DELETE'|'HEAD'|'OPTIONS'|'PATCH')} method - The request method
* @param {object} [options={}] - (optional) The config options of Axios.js (https://goo.gl/UPLqaK)
* @param {object|string} trigger - (optional) The conditions for AUTO RUN, refer the concepts of [conditions](https://reactjs.org/docs/hooks-reference.html#conditionally-firing-an-effect) of useEffect, but ONLY support string and plain object. If the value is a constant, it'll trigger ONLY once at the begining
* @param {function} [forceDispatchEffect=() => true] - (optional) Trigger filter function, only AUTO RUN when get `true`, leave it unset unless you don't want AUTU RUN by all updates of trigger
* @param {function} [customHandler=(error, response) => {}] - (optional) Custom handler callback, NOTE: `error` and `response` will be set to `null` before request
*/
/**
* Returns
* @param {object} response - The response of Axios.js (https://goo.gl/dJ6QcV)
* @param {object} error - HTTP error
* @param {boolean} loading - The loading status
* @param {function} reFetch - MANUAL RUN trigger function for making a request manually
*/
import React, { useState } from 'react';
import useAxios from '@use-hooks/axios';
export default function App() {
const [gender, setGender] = useState('');
const { response, loading, error, reFetch } = useAxios({
url: `https://randomuser.me/api/${gender === 'unknown' ? 'unknown' : ''}`,
method: 'GET',
options: {
params: { gender },
},
trigger: gender,
// or
// trigger: { gender }
forceDispatchEffect: () => !!gender, // AUTO RUN only if gender is set
});
const { data } = response || {};
const options = [
{ gender: 'female', title: 'Female' },
{ gender: 'male', title: 'Male' },
{ gender: 'unknown', title: 'Unknown' },
];
if (loading) return 'loading...';
return (
<div>
<h2>
DEMO of
<span style={{ color: '#F44336' }}>@use-hooks/axios</span>
</h2>
{options.map(item => (
<div key={item.gender}>
<input
type="radio"
id={item.gender}
value={item.gender}
checked={gender === item.gender}
onChange={e => setGender(e.target.value)}
/>
{item.title}
</div>
))}
<button type="button" onClick={reFetch}>
Refresh
</button>
<div>
{error ? (
error.message || 'error'
) : (
<textarea
cols="100"
rows="30"
defaultValue={JSON.stringify(data || {}, '', 2)}
/>
)}
</div>
</div>
);
}
Node >= v8 LTS
npm install
npm start
MIT
Generated by create-react-hooks.
FAQs
Custom React Hooks for Axios.js
The npm package @smartrent/use-axios receives a total of 110 weekly downloads. As such, @smartrent/use-axios popularity was classified as not popular.
We found that @smartrent/use-axios demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.