
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
🐶 React hook for making isomorphic http requests
Need to fetch some data? Try this one out. It's an isomorphic fetch hook. That means it works with SSR (server side rendering).
yarn add use-http
import useFetch from 'use-http'
function App() {
// add whatever other options you would add to `fetch` such as headers
const options = {
onMount: true // will fire on componentDidMount
}
var [data, loading, error, request] = useFetch('https://example.com', options)
// if you want to access the http methods directly using array destructuring, just do
var [data, loading, error, { get, post, patch put, del }] = useFetch('https://example.com', options)
// want to use object destructuring? You can do that too
var { data, loading, error, request, get, post, patch, put, del } = useFetch('https://example.com')
const postData = () => {
post({
no: 'way',
})
// OR
request.post({
no: 'way',
})
}
if (error) return 'Error!'
if (loading) return 'Loading!'
return (
<>
<button onClick={postData}>Post Some Data</button>
<code>
<pre>{data}</pre>
</code>
</>
)
}
You can also do relative routes
const [data, loading, error, request] = useFetch({
baseUrl: 'https://example.com'
})
request.post('/todos', {
id: 'someID',
text: 'this is what my todo is'
})
Or you can use one of the nice helper hooks. All of them accept the second options parameter.
import { useGet, usePost, usePatch, usePut, useDelete } from 'use-http'
const [data, loading, error, patch] = usePatch({
url: 'https://example.com',
headers: {
'Content-type': 'application/json; charset=UTF-8'
}
})
patch({
no: 'way'
})
| Option | Description |
|---|---|
useFetch | The base hook |
useGet | Defaults to a GET request |
usePost | Defaults to a POST request |
usePut | Defaults to a PUT request |
usePatch | Defaults to a PATCH request |
useDelete | Defaults to a DELETE request |
This is exactly what you would pass to the normal js fetch, with a little extra.
| Option | Description | Default |
|---|---|---|
onMount | Once the component mounts, the http request will run immediately | false |
baseUrl | Allows you to set a base path so relative paths can be used for each request :) | empty string |
const {
data,
loading,
error,
request,
get,
post,
patch,
put,
del,
// delete
} = useFetch({
url: 'https://example.com',
baseUrl: 'https://example.com',
onMount: true
})
abort to abort the http request)loading stateFAQs
- useFetch - managed state, request, response, etc. [](https://codesandbox.io/s/usefetch-request-response-managed-state-ruyi3?file=/src/index.js) [](https://w
We found that use-http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.