mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
[react-tracking] Add new Context api (#35504)
This commit is contained in:
parent
695b694eb9
commit
e5ac06081f
8
types/react-tracking/index.d.ts
vendored
8
types/react-tracking/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for react-tracking 5.0
|
||||
// Type definitions for react-tracking 6.0
|
||||
// Project: https://github.com/NYTimes/react-tracking
|
||||
// Definitions by: Eloy Durán <https://github.com/alloy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@ -58,6 +58,12 @@ type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFuncti
|
||||
type MethodDecorator = <T>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
|
||||
export type Decorator = ClassDecorator & MethodDecorator;
|
||||
|
||||
export type TrackingContext<T = any> = React.Context<{
|
||||
tracking: Options<T> & { data?: {} }
|
||||
}>;
|
||||
|
||||
export const ReactTrackingContext: TrackingContext;
|
||||
|
||||
/**
|
||||
* This is the type of the `track` function. It’s declared as an interface so that consumers can extend the typing and
|
||||
* specify defaults, such as a global analytics schema for the tracking-info.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import { Track, track as _track, TrackingProp, Options, Decorator } from 'react-tracking';
|
||||
import { Track, track as _track, TrackingProp, Options, Decorator, TrackingContext, ReactTrackingContext } from 'react-tracking';
|
||||
|
||||
function customEventReporter(data: { page?: string }) {}
|
||||
|
||||
@ -70,3 +70,18 @@ class Test extends React.Component<any, null> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const TestContext = () => {
|
||||
const trackingContext = {
|
||||
tracking: {
|
||||
data: { foo: 'bar' },
|
||||
dispatch: (data: {}) => data,
|
||||
process: (x: string) => x
|
||||
}
|
||||
};
|
||||
return (
|
||||
<ReactTrackingContext.Provider value={trackingContext}>
|
||||
<div>hello how are you</div>
|
||||
</ReactTrackingContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user