mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Merge pull request #27221 from alloy/add-args-to-react-tracking
[react-tracking] The callback variant also passes arguments.
This commit is contained in:
2
types/react-tracking/index.d.ts
vendored
2
types/react-tracking/index.d.ts
vendored
@@ -50,7 +50,7 @@ interface Options<T> {
|
||||
process?(ownTrackingData: T): T | Falsy;
|
||||
}
|
||||
|
||||
export type TrackingInfo<T, P, S> = T | ((props: P, state: S) => T);
|
||||
export type TrackingInfo<T, P, S> = T | ((props: P, state: S, args: any[any]) => T);
|
||||
|
||||
// Duplicated from ES6 lib to remove the `void` typing, otherwise `track` can’t be used as a HOC function that passes
|
||||
// through a JSX component that be used without casting.
|
||||
|
||||
@@ -30,10 +30,15 @@ class ClassPage extends React.Component<Props, State> {
|
||||
// ... other stuff
|
||||
}
|
||||
|
||||
@track((_props, _state, [e]: [React.MouseEvent]) => ({ event: `drag started at ${e.screenX}x${e.screenY}` }))
|
||||
handleDrag(event: React.MouseEvent) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@track((props, state) => ({ event: `got ${props.someProp} and clicked ${state.isClicked}` }))
|
||||
render() {
|
||||
return (
|
||||
<button onClick={this.handleClick}>
|
||||
<button onClick={this.handleClick} onDrag={this.handleDrag}>
|
||||
Click Me!
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -14,6 +14,11 @@ class ClassPage extends React.Component<any> {
|
||||
// ... other stuff
|
||||
}
|
||||
|
||||
@track((_props, _state, [e]) => ({ event: `drag started at ${e.screenX}x${e.screenY}` }))
|
||||
handleDrag(event: any) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
// Only need to cast this to `any` because the settings for this project is to disallow implicit `any`.
|
||||
@track((props: any, state: any) => ({ event: `got ${props.someProp} and clicked ${state.isClicked}` }))
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user