
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
react-state-hooks
Advanced tools
useAsyncState — manage a promise with returning value.useDebounceState — manage a state with debounce, updating the value after a specified delay.useDependentState — manage a state with dependencies.useHistoryState — manage a state, by keeping their history.useListState — manage an array, providing functions to manipulate it.useNumberState — manage a numeric state.useObjectState — manage an object state.usePropState — manage a component prop as state, synchronizing the prop value with the state.useStoreState — manage a global application state.useToggleState — manage a boolean state.// useAsyncState<T>(getter: () => Promise<T>)
// Example:
const userId = 1;
const [user, setUser, { error, isPending, revalidate }] = useAsyncState(getUser, [userId])
async function getUser() {
return {
id: userId,
name: 'Richard',
};
}
// Re-run getter
revalidate()
// useDebounceState<T>(initialValue: T, delay: number = 500)
// Example:
const [debouncedValue, setValue] = useDebounceState('');
// Manual change state
setValue('new value');
// The debounced value will be updated after 500ms of inactivity
// useDependentState<T>(setter: (current?: T) => T, deps: any[])
// Example:
const { user } = useAuth();
const [value, setValue] = useDependentState(() => {
return {
userId: user.id,
page: 1,
}
}, [user]);
// Manual change state
setValue((current) => {
return {
...current,
page: 2
}
});
// useHistoryState<T>(initialState?: T, length: number = 10)
// Example:
const [value, setValue, { history, rollback }] = useHistoryState(0)
// Rollback
setValue(2) // value is now 2
rollback() // value is now 0
// useListState<T>(initialState?: T[])
// Example:
const [list, { set, push, insert, remove, update, clear, sort, filter }] = useListState({ name: 'Richard' })
// Reset
set([1, 2])
// Add
push(3, 4, 5, 6)
// Insert at index
insert(0, 'Hello')
// Remove
remove(0) // by index
remove((item) => item.id === 5) // by handler
// Update
update(0, { name: 'Richard' }) // by index
update((item) => item.id === 5, { name: 'Richard' }) // by handler
// Clear
clear()
// Sort
sort()
sort((a, b) => a.age - b.age)
// Filter
filter((item) => item.age > 21)
// useNumberState(initialState?: number, options?: { min?: number, max?: number, step?: number })
// Example:
const [number, setNumber, { inc, dec }] = useNumberState(0)
// Increment
inc(10)
// Decrement
dec(10)
// Options
const [...] = useNumberState(0, { min: 2, max: 10, step: 2 })
// useObjectState<T>(initialState?: T)
// Example:
const [obj, updateObj, resetObj] = useObjectState({ name: 'Richard' })
// Update
updateObj({ age: 21 });
// Reset
resetObj({});
// usePropState<T>(prop: T | undefined, initialState?: T | (() => T))
// Example:
const [name, setName] = usePropState(props.name, 'Richard')
// useStoreState<T>(key: string, initialState?: T | (() => T))
// Example:
const [name, setName] = useStoreState('user.name', 'Richard')
// useToggleState(initialState?: boolean)
// Example:
const [isVisible, toggleIsVisible] = useToggleState(false)
FAQs
Collection of hooks to manage state.
We found that react-state-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.