-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from gregnb/use-appendChild
Use append child
- Loading branch information
Showing
5 changed files
with
855 additions
and
887 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from "react"; | ||
|
||
import ReactToPrint from "../../src/index"; | ||
|
||
type Props = Record<string, unknown>; | ||
type State = { | ||
isLoading: boolean; | ||
text: string; | ||
}; | ||
|
||
class TextComponent extends React.PureComponent { | ||
render() { | ||
return 'This is bare text'; | ||
} | ||
} | ||
|
||
export class ClassComponentText extends React.PureComponent<Props, State> { | ||
componentRef: TextComponent | null = null; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
isLoading: false, | ||
text: "old boring text", | ||
}; | ||
} | ||
|
||
setComponentRef = (ref: TextComponent) => { | ||
this.componentRef = ref; | ||
} | ||
|
||
reactToPrintContent = () => { | ||
return this.componentRef; | ||
} | ||
|
||
reactToPrintTrigger = () => { | ||
// NOTE: could just as easily return <SomeComponent />. Do NOT pass an `onClick` prop | ||
// to the root node of the returned component as it will be overwritten. | ||
|
||
// Bad: the `onClick` here will be overwritten by `react-to-print` | ||
// return <button onClick={() => alert('This will not work')}>Print this out!</button>; | ||
|
||
// Good | ||
return <button>Print pure text using a Class Component</button>; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<ReactToPrint | ||
content={this.reactToPrintContent} | ||
documentTitle="AwesomeFileName" | ||
removeAfterPrint | ||
trigger={this.reactToPrintTrigger} | ||
/> | ||
{this.state.isLoading && <p className="indicator">onBeforeGetContent: Loading...</p>} | ||
<TextComponent ref={this.setComponentRef} /> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.