在浏览器中打印 React 组件
# ReactToPrint - Print React components in the browser Print the content of a React component. `npm install --save react-to-print` ## Demo ## Usage ```tsx import { useReactToPrint } from "react-to-print"; import { useRef } from "react"; const contentRef = useRef(null); const reactToPrintFn = useReactToPrint({ contentRef }); return ( ); ``` It is also possible to lazy set the ref if your content being printed is dynamic. See the [`LazyContent`](https://github.com/MatthewHerbst/react-to-print/blob/master/examples/LazyContent/index.tsx) example for more. This can also be useful for setting the ref in non-React code, such as util functions. ## API | Option | Type | Description | | :-------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------- | | **`bodyClass`** | `string` | One or more class names to pass to the print window, separated by spaces | | **`contentRef`** | `React.RefObject` | The ref pointing to the content to be printed. Alternatively, pass the ref directly to the callback returned by `useReactToPrint` | | **`copyShadowRoots`** | `boolean` | Copy shadow root content into the print window. Warning: Use with care if you print large documents as traversing these can be slow. | | **`documentTitle`** | `string \| (() => string)` | Set the title for printing when saving as a file. This is useful for including dynamic data like timestamps. Ignored when passing a custom `print` option | | **`fonts`** | `{ family: string, source: string; weight?: string; style?: string; }[]` | A list of fonts to load into the printing iframe. This is useful if you are using custom fonts | | **`ignoreGlobalStyles`** | `boolean` | Ignore all `
暂无开放 Issues,或尚未同步最近议题。