
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
use-suspensible
Advanced tools

React hooks that can make any data suspensible.
This is a proof-of-concept for using Suspense with non-promise based async libraries. Also see observable-hooks on implementing Render-as-You-Fetch pattern with Suspense and Rxjs Observable.
yarn
yarn add use-suspensible
npm
npm install --save use-suspensible
import React, { Suspense, useState, useEffect } from 'react'
import { useSuspensible } from 'use-suspensible'
function fetchData() {
return new Promise(resolve => {
setTimeout(() => {
resolve({ content: "content" })
}, 3000)
})
}
const App = () => {
const [data, setData] = useState()
useEffect(
() => {
fetchData().then(setData)
},
[]
)
return (
<Suspense fallback={<h1>Loading...</h1>}>
<Content data={data} />
</Suspense>
)
}
function Content({ data }) {
useSuspensible(data)
return (
<h1>{data.content}</h1>
);
}
Default trigger Suspense on null or undefined.
useSuspensible(data)
Custom comparison for checking finish state.
useSuspensible(data, data => data.status === 'finish')
You can have any number of useSuspensible in a Component.
useSuspensible(data1)
useSuspensible(data2)
useSuspensible(data3, data => data.status === 'finish')
return (
<>
<h1>{data1.content}</h1>
<h1>{data2.content}</h1>
<h1>{data3.content}</h1>
</>
)
TypeScript >= 3.7
interface StatePending {
status: 'pending'
value: null
}
interface StateFinish {
status: 'finish'
value: number
}
type States = StatePending | StateFinish
//....
useSuspensible(
data,
(data: States): data is StateFinish => data.status === 'finish'
)
// Now data is of `StateFinish` type.
Due to the design of Suspense, each time a suspender is thrown, the children of Suspense Component will be destroyed and reloaded. Do not initialize async data and trigger Suspense in the same Component.
import React, { Suspense, useState, useEffect } from 'react'
import { useSuspensible } from 'use-suspensible'
function fetchData() {
return new Promise(resolve => {
setTimeout(() => {
resolve({ content: "content" })
}, 3000)
})
}
const App = () => {
return (
<Suspense fallback={<h1>Loading...</h1>}>
<Content />
</Suspense>
)
}
function Content({ data }) {
const [data, setData] = useState()
// This will cause infinite update.
useEffect(
() => {
fetchData().then(setData)
},
[]
)
useSuspensible(data)
return (
<h1>{data.content}</h1>
);
}
FAQs
A React hook that can make any data suspensible.
We found that use-suspensible 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.