THE MEETUP
React Meetup #91
- When
- Sat 31 May 2025 · 14:00–18:00 IST
- Where
- Scaler School of Technology, Bengaluru
- Group
- React Bangalore
TALK · REACT MEETUP #91 · 31 MAY 2025
Local state sprawl, prop drilling, Redux boilerplate and Context re-renders, and how Zustand replaces them with one hook. Every example is updated for Zustand v5, and the re-render lab lets you see the difference.
THE MEETUP
REACT MEETUP #91
PART 1
Dozens of useState hooks across files.
Passing setters through 3–4 component levels.
3 files just to update one value.
Every consumer re-renders on any state change.
You still write the slice, connect and dispatch.

PART 2
About 1 KB gzipped. No Provider. Hook-based.
create() call → your useStore hookSubscribe + 1 update on 10k items
Figures as presented at the talk.
What each library adds next to React
Figures as presented at the talk.
PART 3
import { create } from 'zustand'
const useStore = create(set => ({
count: 0,
inc: () => set(s => ({ count: s.count + 1 }))
}))UPDATED SINCE THE TALKThe slide used import create from 'zustand'. Zustand v5 dropped default exports, so it’s now import { create } from 'zustand'.
PART 4
| Redux | Zustand | |
|---|---|---|
| Boilerplate | High | Minimal |
| Provider | Required | None |
| Bundle (gzip) | ~5 KB | ~1 KB |

PART 5
// counterSlice.ts
import { createSlice } from '@reduxjs/toolkit'
// 1. Define slice with initial state + reducer
const counterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
inc: (state) => state + 1
}
})
// 2. Export action creator and reducer
export const { inc } = counterSlice.actions
export default counterSlice.reducer// store.ts
import { configureStore } from '@reduxjs/toolkit'
import counterReducer from './counterSlice'
// Create Redux store with our slice reducer
export const store = configureStore({
reducer: {
counter: counterReducer
}
})// index.tsx
import React from 'react'
import { createRoot } from 'react-dom/client'
import { Provider } from 'react-redux'
import App from './App'
import { store } from './store'
// Wrap your app in the Redux Provider
createRoot(document.getElementById('root')).render(
<Provider store={store}>
<App />
</Provider>
)UPDATED SINCE THE TALKThe slide used ReactDOM.render, which React 18 replaced with createRoot and React 19 removed.
// Counter.tsx
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { inc } from './counterSlice'
export function Counter() {
// Read state and get dispatch
const count = useSelector((state: { counter: number }) => state.counter)
const dispatch = useDispatch()
return (
<button onClick={() => dispatch(inc())}>
Count: {count}
</button>
)
}useSelector + useDispatch3 files + Provider, before the component even renders.
// store.ts (4 lines)
import { create } from 'zustand'
export const useStore = create((set) => ({
count: 0,
inc: () => set((s) => ({ count: s.count + 1 })),
}))// Counter.tsx
import { useStore } from './store'
export function Counter() {
const count = useStore((s) => s.count)
const inc = useStore((s) => s.inc)
return <button onClick={inc}>{count}</button>
}UPDATED SINCE THE TALKThe slide picked both values with one object selector, useStore(s => ({ count: s.count, inc: s.inc })). In Zustand v5 a selector that returns a new object every time can loop until React throws “Maximum update depth exceeded”, so this uses two selectors (or wrap the object in useShallow).
useStore, zero slice/store wiring
PART 6
Selecting, updating and optimising state access
// store.ts
import { create } from 'zustand'
export const useStore = create(set => ({
user: {
name: { first: 'Alice', last: 'Doe' },
email: 'alice@example.com',
preferences: { theme: 'dark', notifications: true }
},
// updater functions omitted
}))// Subscribe only to `user.name.first`
const firstName = useStore(state => state.user.name.first)
return <div>User First Name: {firstName}</div>// store.ts
import { create } from 'zustand'
export const useStore = create(set => ({
user: {
name: { first: 'Alice', last: 'Doe' },
preferences: { theme: 'light', notifications: true }
},
setTheme: (newTheme: string) =>
set(state => ({
user: {
...state.user,
preferences: { ...state.user.preferences, theme: newTheme }
}
}))
}))// Get updater for nested piece of state
const setTheme = useStore(state => state.setTheme)
return (
<button onClick={() => setTheme('dark')}>
Switch to Dark Theme
</button>
)import { useShallow } from 'zustand/react/shallow'
// Combined selector: read firstName + theme updater
const { firstName, setTheme, currentTheme } = useStore(
useShallow(state => ({
firstName: state.user.name.first,
setTheme: state.setTheme,
currentTheme: state.user.preferences.theme
}))
)
return (
<>
<p>Welcome, {firstName}!</p>
<p>Current Theme: {currentTheme}</p>
<button onClick={() => setTheme('dark')}>Dark Mode</button>
</>
)UPDATED SINCE THE TALKThe slide passed shallow as a second argument to useStore. v5’s create no longer takes an equality function; wrap the selector in useShallow instead.
Four components share one store. Pick how they read it, then change something and watch who re-renders. A model of the rule each approach uses: Context re-renders every consumer; a Zustand selector re-renders only when what it returns changes (Object.is, or a shallow compare with useShallow).
HOW COMPONENTS READ STATE
CHANGE THE STATE
Change something to see who re-renders.
PART 7
// todosStore.ts
import { create } from 'zustand'
export const useTodosStore = create(set => ({
todos: [] as string[],
add: (todo: string) => set(s => ({ todos: [...s.todos, todo] }))
}))
// userStore.ts
import { create } from 'zustand'
export const useUserStore = create(set => ({
user: null as User | null,
login: (u: User) => set({ user: u })
}))// store.ts
import { devtools, persist } from 'zustand/middleware'
import { create } from 'zustand'
export const useStore = create(
devtools(
persist(
set => ({
count: 0,
inc: () => set(s => ({ count: s.count + 1 }))
}),
{ name: 'counter-storage' }
)
)
)PART 8
// Subscribe only to what you need
const count = useStore(state => state.count)
return <div>Count: {count}</div>// ❌ Creates new object each call
useStore(s => ({ count: s.count }))
// ✅ Separate subscriptions
const count = useStore(s => s.count)
const inc = useStore(s => s.inc)EVEN MORE TRUE IN V5An inline object selector used to cost a wasted re-render; in Zustand v5 it can loop forever. Split the subscriptions, or wrap the selector in useShallow.