Docs

Performance Optimizations

SuperState is built from the ground up for speed. It uses React 18's useSyncExternalStore to minimize re-renders and ensure consistency across your application.

#Selective Re-renders

Only components watching a specific key re-render. If you have 500 components and 1 component updates "count", 499 components will not even be evaluated.

ts
AppOverview.tsx
import { useSuperState } from "react-use-superstate"
function Counter() {
const [count] = useSuperState('count') // Watches focus: count
return <h1>{count}</h1>
}
function Sidebar() {
// Watches focus: user.name
// Will NEVER re-render if count changes
const [name] = useSuperState('user.name')
return <span>{name}</span>
}

#Batching Updates

When updating multiple keys at once, wrap your updates in batchUpdate to bundle them into a single notification. This prevents multiple re-renders for a single interaction.

ts
app/page.tsx
import { batchUpdate, setState } from "react-use-superstate"
// Use batching for multiple updates
batchUpdate(() => {
setState('loading', true)
setState('userId', 101)
setState('theme', 'dark')
})
// All watchers re-render only ONCE.
External Sync
Because SuperState exists outside the React render tree, it bypasses top-down reconciliation for global updates, which can significantly improve TBT (Total Blocking Time) in large apps.