Debugging Guide for zustand-getters
December 19, 2025 ยท View on GitHub
Quick Start
1. Install Dependencies
bun install
2. Build the Package
bun run build
3. Run the Example App
cd example
bun install
bun run dev
Open http://localhost:5173 in your browser.
Development Workflow
Watch Mode (Auto-rebuild on changes)
# Terminal 1: Watch and rebuild the middleware
bun run dev
# Terminal 2: Run the example app
cd example && bun run dev
Type Checking
# Check types without building
bun run typecheck
# Check types in example
cd example && bun run build
Linting & Formatting
# Lint and auto-fix issues
bun run lint
# Format code
bun run format
Debugging Techniques
1. Console Logging in the Middleware
Edit src/index.ts and add console logs:
export const getters: GettersMiddleware = (stateCreator) => {
return (set, get, store) => {
const state = stateCreator(set, get, store);
console.log('๐ Initial state:', state);
// Wrap all getters to make them reactive
wrapAllGetters(state, () => set((currentState) => currentState));
console.log('๐ State after wrapping getters:', state);
return state;
};
};
2. Test in Example App
The example app (example/src/App.tsx) has several examples:
- Basic counter with reactive getters
- User store with fullName and initials getters
- Shopping cart with chained getters
- Todo list with immer integration
Add your own test cases in example/src/store.ts:
export const useDebugStore = create<DebugStore>()(
getters((set) => ({
// Your test state here
value: 'test',
count: 0,
// Reactive getter
get double() {
return this.count * 2;
},
})),
);
3. Inspect Store State
In the browser console:
// Get the store
const store = window.useCounterStore || useCounterStore;
// Check current state
console.log(store.getState());
// Check available getters
console.log(Object.keys(store.getState()).filter((k) => k.startsWith('get')));
// Call a getter
console.log(store.getState().getCount());
4. React DevTools
- Install React DevTools browser extension
- Open DevTools โ Components tab
- Select a component using the store
- View props and state in real-time
5. Zustand DevTools (Optional)
Add devtools middleware to debug state changes:
import { devtools } from 'zustand/middleware';
import { getters } from '@csark0812/zustand-getters';
const useStore = create<Store>()(
devtools(
getters((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
})),
{ name: 'MyStore' },
),
);
Then open Redux DevTools extension to see state changes.
Common Issues
Issue: "Cannot find module"
Solution: Run bun install in both root and example directories
Issue: Changes not reflecting
Solution:
- Stop the dev server
- Run
bun run buildin root - Restart example app
Issue: Type errors
Solution:
- Check
tsconfig.jsonsettings - Run
bun run typecheck - Ensure Zustand version is compatible (^4.0.0 || ^5.0.0)
Issue: ESLint/Prettier conflicts
Solution:
- Run
bun run formatto format with Prettier - Run
bun run lintto fix ESLint issues - Check
.vscode/settings.jsonfor editor config
Issue: Getters not updating components
Solution:
- Make sure you're selecting the getter in your component:
useStore((state) => state.myGetter) - Verify the getter is defined with
get propertyName()syntax - Check that the getter dependencies are being updated immutably
- Log the wrapped getters (see technique #1)
Testing Changes
Manual Testing Checklist
- Build succeeds:
bun run build - Types are valid:
bun run typecheck - Linting passes:
bun run lint - Formatting is clean:
bun run format - Example app runs:
cd example && bun run dev - Getters work in browser console
- State updates trigger re-renders
Test Different Scenarios
- Basic usage - Simple getters with single dependencies
- Chained getters - Getters that depend on other getters
- Nested objects - Getters in nested object structures
- With other middleware - devtools, persist, immer
- Complex computations - Array operations, mathematical calculations
Build Output
After running bun run build, check the dist/ folder:
dist/
โโโ index.js # ESM build
โโโ index.cjs # CommonJS build
โโโ index.d.ts # TypeScript types
โโโ index.d.ts.map # Source map for types
Verify the build:
# Check file sizes
ls -lh dist/
# Inspect the output
cat dist/index.js | head -20
Publishing Checklist
Before publishing:
- All tests pass
- Documentation is updated
- CHANGELOG.md is updated
- Version is bumped
- Build is clean
- Example app works with built version
Need Help?
- Check the README.md for usage examples
- Review GETTING_STARTED.md for basics
- Look at the example app for working code
- Open an issue on GitHub