diff --git a/packages/react-on/src/lib/handlers.tsx b/packages/react-on/src/lib/handlers.tsx index f39e8c6..5ca0564 100644 --- a/packages/react-on/src/lib/handlers.tsx +++ b/packages/react-on/src/lib/handlers.tsx @@ -64,13 +64,13 @@ export function createTrackingHandlerProvider; } - function useTrack() { + function useTrack({ values }: { values?: Partial } = {}) { const handler = useContext(handlerCtx).handle; const ctxValue = useContext(ctx); return useStableCallback((options) => { if (ctxValue.enabled) { - handler({ ...options, values: { ...ctxValue.values, ...options?.values } as TValues }); + handler({ ...options, values: { ...ctxValue.values, ...values, ...options?.values } as TValues }); } }); } diff --git a/packages/react-on/src/lib/track-callback.tsx b/packages/react-on/src/lib/track-callback.tsx index 4cf62f2..ee116c0 100644 --- a/packages/react-on/src/lib/track-callback.tsx +++ b/packages/react-on/src/lib/track-callback.tsx @@ -11,7 +11,7 @@ export function createTrackCallback(useTrac function TrackCallback< ComponentType = DOMAttributes, CallbackName extends PropertyKey = CallbackNames | (string & {}), - >({ children, callback, name, disabled, ...props }: TProps & { callback: CallbackName }) { + >({ children, callback, name, disabled, values, ...props }: TProps & { callback: CallbackName }) { children = Children.only(children) as ReactElement; if (!children) throw new Error('Children passed to track directive must be an element with ref'); @@ -19,10 +19,7 @@ export function createTrackCallback(useTrac const resolvedName = name ?? String(callback); const track = useTrack(); - - const trackFn = useStableCallback((...args: any[]) => - track({ values: props.values, args: [resolvedName, ...args] }), - ); + const trackFn = useStableCallback((...args: any[]) => track({ values, args: [resolvedName, ...args] })); const originalCallback = children.props[callback]; const handle = useCallback( diff --git a/packages/react-on/src/lib/track-event.tsx b/packages/react-on/src/lib/track-event.tsx index 976710c..eca2287 100644 --- a/packages/react-on/src/lib/track-event.tsx +++ b/packages/react-on/src/lib/track-event.tsx @@ -23,7 +23,8 @@ export function createTrackEvent(useTrack: const resolvedName = name ?? event; const track = useTrack(); - const trackFn = useStableCallback((...args: any[]) => track({ values: values, args: [resolvedName, ...args] })); + const trackFn = useStableCallback((...args: any[]) => track({ values, args: [resolvedName, ...args] })); + const handle = useCallback( (ev: HTMLElementEventMap[EventName], ...args: any[]) => { trackFn(ev, ...args);