Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
treble-hook
Advanced tools
yarn add treble-hook
or
npm install --save treble-hook
Contrived sign-in component along with component that displays active user (signed-in user).
import React, { ChangeEvent, useState } from 'react'
import { usePubSub } from 'treble-hook'
const ACTIVE_USER_TOPIC = 'active-user'
function SignIn() {
// publishUser will do just that, publish the value
// to all subscribers of the ACTIVE_USER_TOPIC
const [_, publishUser] = usePubSub<string>(ACTIVE_USER_TOPIC, '')
const [entered, setEntered] = useState<string>('')
return (
<div>
<input
type='text'
onChange={
(evt: ChangeEvent<HTMLInputElement>) => {
setEntered(evt.target.value)
}
}
/>
<button onClick={ () => { publishUser(entered) }}>Sign-in</button>
</div>
)
}
function ActiveUser() {
// this subsribes the component to the ACTIVE_USER_TOPIC and
// whenever the active user is published (from anywhere in the
// app) it will get updated here. Also, this component doesn't
// have to wait for the next publish, it will intialize with
// the last published value or default to 'Anonymous' otherwise
const [activeUser] = usePubSub<string>(
ACTIVE_USER_TOPIC,
'Anonymous'
)
return (
<div>
Active user: { activeUser }
</div>
)
}
Brought to you by the engineering team at Igneous. Speaking of, we're always on the lookout for fun-loving, passionate engineers; visit Igneous culture and careers to learn more.
FAQs
Get hooked on simple subscribe-and-publish in ReactJS.
The npm package treble-hook receives a total of 34 weekly downloads. As such, treble-hook popularity was classified as not popular.
We found that treble-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.