Skip to content

Commit

Permalink
Ensure event argument is optional (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHerbst authored Feb 14, 2024
1 parent 223730c commit d172651
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/PrintContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from "react";
const contextEnabled = Object.prototype.hasOwnProperty.call(React, "createContext");

export interface IPrintContextProps {
handlePrint: (event: unknown, content?: (() => React.ReactInstance | null)) => void,
handlePrint: (event?: unknown, content?: (() => React.ReactInstance | null)) => void,
}

export const PrintContext = contextEnabled ? React.createContext({} as IPrintContextProps) : null;
Expand Down
4 changes: 1 addition & 3 deletions src/components/ReactToPrint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ export class ReactToPrint extends React.Component<IReactToPrintProps> {
}

public handleClick (
/* eslint-disable-next-line no-unused-vars */
// @ts-expect-error variable is unused
event: unknown,
_event?: unknown,
content?: (() => React.ReactInstance | null)
) {
const {
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useReactToPrint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { IReactToPrintProps } from "../types/reactToPrintProps";
import { wrapCallbackWithArgs } from "../utils/wrapCallbackWithArgs";

type UseReactToPrintHookReturn = (
event: unknown,
event?: unknown,
content?: (() => React.ReactInstance | null)
) => void;

Expand All @@ -30,11 +30,10 @@ export const useReactToPrint = (props: IReactToPrintProps): UseReactToPrintHookR
);

return React.useCallback(
(event: unknown, content?: (() => React.ReactInstance | null)) => {
(event?: unknown, content?: (() => React.ReactInstance | null)) => {
/* eslint-disable-next-line @typescript-eslint/unbound-method */
const triggerPrint = wrapCallbackWithArgs(reactToPrint, reactToPrint.handleClick, content);
// NOTE: `event` is a no-use argument
// (necessary for backward compatibility with older versions)
// NOTE: `event` is an unused argument, necessary for backward compatibility with older versions
return triggerPrint(event);
}, [reactToPrint]);
};
2 changes: 1 addition & 1 deletion src/types/reactToPrintProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Font } from "./font";

export interface ITriggerProps<T> {
onClick: (event: unknown) => void;
onClick: (event?: unknown) => void;
ref: (v: T) => void;
}

Expand Down

0 comments on commit d172651

Please sign in to comment.