Zustand
Este plugin te permite capturar las mutaciones/el estado de Zustand e inspeccionarlos más adelante mientras reproduces las grabaciones de sesiones. Esto resulta muy útil para entender y solucionar problemas.
Instalación
Section titled Instalaciónnpm i @openreplay/tracker-zustand
Inicializa el paquete @openreplay/tracker como de costumbre y carga el plugin en él. Llama al plugin para configurar el nombre del store; esto devolverá una instancia de tracker de store con nombre que puedes invocar pasando tu ejemplar de store como argumento para habilitar el seguimiento de dicho store.
Si tu sitio web es una Single Page Application (SPA)
Section titled Si tu sitio web es una Single Page Application (SPA)import Tracker from '@openreplay/tracker';
import trackerZustand from '@openreplay/tracker-zustand';
Si tu aplicación web es Server-Side-Rendered (SSR)
Section titled Si tu aplicación web es Server-Side-Rendered (SSR)import Tracker from '@openreplay/tracker/cjs';
import trackerZustand from '@openreplay/tracker-zustand/cjs';
Seguimiento del store de Zustand
Section titled Seguimiento del store de Zustandimport create from "zustand";
const tracker = new Tracker({
projectKey: YOUR_PROJECT_KEY,
});
const zustandPlugin = tracker.use(trackerZustand())
// name is optional, randomly generated
// string if its undefined
const bearStoreLogger = zustandPlugin('bear_store')
const useBearStore = create(
bearStoreLogger((set: any) => ({
bears: 0,
increasePopulation: () => set((state: any) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
}))
)
Opciones
Section titled OpcionesPuedes personalizar el comportamiento del plugin con opciones para sanear tus datos. Son similares a las del plugin estándar createLogger.
trackerZustand({
filter (mutation, state) {
// returns `true` if a mutation should be logged
// `mutation` is a `{ type, payload }`
return mutation.type !== "aBlacklistedMutation";
},
transformer (state) {
// transforms the state before logging it.
// for example return only a specific sub-tree
return state.subTree;
},
mutationTransformer (mutation) {
// mutations are logged in the format of `{ type, payload }`
// we can format it any way we want.
return mutation.type;
},
})
¿Tienes preguntas?
Section titled ¿Tienes preguntas?¿Tienes problemas para configurar este plugin? Conéctate a nuestro Slack o visita nuestro Foro y obtén ayuda de nuestra comunidad.