
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.
watchi-store
Advanced tools
Watchi-store is a simple typescript compatible state management library for React, focused on controllability and performance.
It's inspired by libraries like Redux, Zustand and MobX. The main difference between these libraries and Watchi-store is that this library does not enforce immutability in the store, changes anywhere in the store will cause watchers (listeners) and corresponding UI to be automatically updated. This can be useful when working with a large amount of deeply nested state that you want to control outside of the individual UI components, for example from actions.
This library will most likely not offer any benefits if you are not working with large amounts of nested states or need improved state performance.
Create a store
import Store from 'watchi-store'
type MyStore = { a: { [key: string]: { name: string; n: number } } }
const myStore = new Store<MyStore>({
a: {
b1: {
name: 'my name'
n: 0,
},
b2: {
name: 'my name'
n: 1,
}
}
})
Watch store values
function MyComponent() {
const b2n = myStore.useWatch(store => store.a.b2.n)
return <div onClick={() => myStore.store.a.b2.n++}>b2n: {b2n}</div>
}
Watch store values based on props (don't search through store)
function A(){
const a = useWatch(store => store.a)
return <>
<B b={a.b1} />
<B b={a.b2} />
</>
}
function B(props: { b: { n: number }, increment: () => void }) {
// watch value from props, same reference as from store
const n = useWatch(() => props.b.n)
return <button onClick={() => props.b.n++}>{props.b.name}: {n}</button>
}
Update the store from anywhere
const time = new Store({ passed: 0 })
setTimeout(() => time.store.passed++, 1000)
function Passed() {
const passed = time.useWatch(store => store.passed)
return <div>{passed} has passed</div>
}
useRefWatch(): Watch store without rerendering UI on changes
watch(): Call callback whenever the store updates
revertable(): Perform a revertable action on the store
revertableGlobal(): Like revertable but any changes made during the action will can be reverted, including changes outside of the action
transaction(): Perform a transaction on the store, changes to the store will only be applied when the transactions finishes successfully
revertOnError(): Perform a revertable action on the store, actions are reverted when an error is caught
revertOnErrorGlobal(): Like revertOnError but reverts all changes made during the action, including changes outside of the action
target(): Returns the original unwatched object of a watched object
FAQs
Small, controllable and performant state management for React
The npm package watchi-store receives a total of 0 weekly downloads. As such, watchi-store popularity was classified as not popular.
We found that watchi-store 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.

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.