Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@hazae41/glacier
Advanced tools
npm i @hazae41/glacier
Node Package 📦 • Read the docs 📚 • Next.js Example 🪣 • Expo Example 🪣 • Comparison with other libs 🌐
Glacier uses two new approaches compared to other data fetching libraries like swr or react-query:
Just install @hazae41/glacier
using your favorite package manager.
npm i @hazae41/glacier
Then, wrap your app in a CoreProvider
component.
import { CoreProvider } from "@hazae41/glacier"
function MyWrapper() {
return <CoreProvider>
<MyAwesomeApp />
</CoreProvider>
}
When using Glacier and its composition-based hooks, you create a mix and only include the ingredients you want.
We'll do a request at /api/data
using JSON, display it with a loading, and automatically refetch it.
It will just take an url, fetch it, and return the data.
async function fetchAsJson<T>(url: string) {
const res = await fetch(url)
const data = await res.json() as T
return { data }
}
Then create a mix using a query and some blocks.
function useHello() {
const query = useQuery<Hello>(`/api/hello`, fetchAsJson)
useFetch(query) // Fetch on mount and on url change
useVisible(query) // Fetch when the page becomes visible
useOnline(query) // Fetch when the browser becomes online
return query
}
function MyApp() {
const { data, error } = useHello()
if (error)
return <MyError error={error} />
if (!data)
return <MyLoading />
return <MyPage data={data} />
}
Last example was good, but here is the best way to use Glacier.
Our fetcher was good, but this one can be aborted.
async function fetchAsJson<T>(url: string, more: FetcherMore<T>) {
const { signal } = more
const res = await fetch(url, { signal })
if (!res.ok) {
const error = new Error(await res.text())
return { error }
}
const data = await res.json() as T
return { data }
}
It also returns an error if the request failed.
Using schemas may seems boilerplate, but it will save you a lot of time later.
function getHelloSchema() {
return getSchema<Hello>("/api/hello", fetchAsJson)
}
It allows you to reuse the same set of key+fetcher+params in multiple places, including imperative code.
The mixtures pattern allows you to reuse the same group of blocks.
function useAutoFetchMixture(query: Query) {
useFetch(query)
useVisible(query)
useOnline(query)
}
Once you got a schema and a mixture, you just have to mix it.
function useHelloMix() {
const query = useSchema(getHelloSchema, [])
useAutoFetchMixture(query)
return query
}
function MyApp() {
const { data, error } = useHelloMix()
if (error)
return <MyError error={error} />
if (!data)
return <MyLoading />
return <MyPage data={data} />
}
FAQs
Yet another React data (re)fetching library
The npm package @hazae41/glacier receives a total of 361 weekly downloads. As such, @hazae41/glacier popularity was classified as not popular.
We found that @hazae41/glacier demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.