OpenReplay Tracker Zustand plugin
A Zustand plugin for OpenReplay Tracker. This plugin allows you to see the application state during session replay.
Installation
npm i @openreplay/tracker-zustand
Usage
Initialize the @openreplay/tracker package as usual and load the plugin into it.
Then put the generated plugin into your plugins field of your store.
import create from "zustand";
import Tracker from '@openreplay/tracker';
import trackerZustand, { StateLogger } from '@openreplay/tracker-zustand';
const tracker = new Tracker({
projectKey: YOUR_PROJECT_KEY,
});
const zustandPlugin = tracker.use(trackerZustand()) as unknown as StateLogger
const useBearStore = create(
zustandPlugin((set: any) => ({
bears: 0,
increasePopulation: () => set((state: any) => ({ bears: state.bears + 1 })),
removeAllBears: () => set({ bears: 0 }),
}),
'bear_store'
)
)
You can customize the plugin behavior with options to sanitize your data. They are similar to the ones from the standard createLogger plugin.
trackerZustand({
filter (mutation, state) {
return mutation.type !== "aBlacklistedMutation";
},
transformer (state) {
return state.subTree;
},
mutationTransformer (mutation) {
return mutation.type;
},
})