Skip to content

Commit

Permalink
Merge pull request #220 from invious/master
Browse files Browse the repository at this point in the history
supress errors boolean prop
  • Loading branch information
MatthewHerbst authored Mar 2, 2020
2 parents 5a910af + 37edae3 commit 6352e21
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface IReactToPrintProps {
bodyClass?: string;
/** Optional - remove the iframe after printing. */
removeAfterPrint?: boolean;
/** Optional - suppress error messages */
suppressErrors?: boolean;
}

export default class ReactToPrint extends React.Component<IReactToPrintProps> {
Expand Down Expand Up @@ -110,12 +112,15 @@ export default class ReactToPrint extends React.Component<IReactToPrintProps> {
content,
copyStyles = true,
pageStyle,
suppressErrors,
} = this.props;

const contentEl = content();

if (contentEl === undefined) {
console.error('Refs are not available for stateless components. For "react-to-print" to work only Class based components can be printed'); // tslint:disable-line max-line-length no-console
if (!suppressErrors) {
console.error('Refs are not available for stateless components. For "react-to-print" to work only Class based components can be printed'); // tslint:disable-line max-line-length no-console
}
return;
}

Expand All @@ -136,7 +141,9 @@ export default class ReactToPrint extends React.Component<IReactToPrintProps> {
if (loaded) {
this.linksLoaded.push(linkNode);
} else {
console.error('"react-to-print" was unable to load a link. It may be invalid. "react-to-print" will continue attempting to print the page. The link the errored was:', linkNode); // tslint:disable-line max-line-length no-console
if (!suppressErrors) {
console.error('"react-to-print" was unable to load a link. It may be invalid. "react-to-print" will continue attempting to print the page. The link the errored was:', linkNode); // tslint:disable-line max-line-length no-console
}
this.linksErrored.push(linkNode);
}

Expand Down

0 comments on commit 6352e21

Please sign in to comment.