{"library":"sentry-zustand-middleware","title":"Sentry Zustand Middleware","description":"sentry-zustand-middleware is a specialized middleware for Zustand stores designed to automatically log state changes and actions to Sentry. This package is currently at version 4.3.0 and typically follows the release cycles of its peer dependencies, Zustand and Sentry, to ensure compatibility. Its core function is to capture the state snapshots and the actions that modify them, providing enhanced debugging capabilities and visibility into application state flow during error reporting. A key differentiator is its optional `stateTransformer` function, which allows developers to clean, filter, or obfuscate sensitive data from the Zustand state before it is sent to Sentry, preventing oversharing of private information. It provides a direct integration without manual Sentry calls within every action or state update.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install sentry-zustand-middleware"],"cli":null},"imports":["import sentryMiddleware from 'sentry-zustand-middleware';","import type { SentryZustandMiddlewareOptions } from 'sentry-zustand-middleware';","import create from 'zustand';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import create from 'zustand';\nimport sentryMiddleware from 'sentry-zustand-middleware';\n\n// Ensure Sentry is initialized elsewhere in your application entry point\n// For example:\n// import * as Sentry from '@sentry/browser';\n// Sentry.init({ dsn: process.env.SENTRY_DSN ?? '' });\n\ninterface BearState {\n  bears: number;\n  increase: (by: number) => void;\n  decrease: (by: number) => void;\n  logSomething: (message: string) => void;\n}\n\nconst useStore = create<BearState>()(\n  sentryMiddleware((set) => ({\n    bears: 0,\n    increase: (by) => {\n      set((state) => ({ bears: state.bears + by }), false, 'increaseBears');\n    },\n    decrease: (by) => {\n      set((state) => ({ bears: state.bears - by }), false, 'decreaseBears');\n    },\n    logSomething: (message) => {\n      // This action will also be logged by the middleware\n      console.log(message);\n    }\n  })),\n);\n\n// Example usage (ensure Sentry is initialized for actual logging)\nconst store = useStore.getState();\nstore.increase(5);\nstore.decrease(2);\n\nconsole.log('Current bears:', useStore.getState().bears);\n","lang":"typescript","description":"This quickstart demonstrates basic integration of `sentry-zustand-middleware` with a Zustand store, logging state changes and actions to Sentry (assuming Sentry is initialized).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}