提问人:Dev Anand Sadasivam 提问时间:3/10/2023 最后编辑:Dev Anand Sadasivam 更新时间:3/10/2023 访问量:76
如何在 React 应用程序中启用打印,其中页面呈现为 <Route 下的部分>
How to enable print in React application where page rendered as section under <Route>
问:
我已经启用了模块,react-to-print
import { useReactToPrint } from "react-to-print";
在本代码中,调用了 。App.jsx
main-presenter.jsx
import MainPresenter, {FLOW_PATH, MEMBER_HOME} from './presenters/main-presenter';
在 中,我有这样的代码,main-presenter.jsx
....
export const CONFIRMATION_PATH = '/confirmation';
....
return (
<React.Fragment>
.....
<Route path={CONFIRMATION_PATH} render={() => <SectionPresenter section={confirmationSection} key={confirmationSection} returnToCart={props.returnToCart} openExitModal=
{props.openExitModal}/>}/>
.....
</React.Fragment>
);
我如何复杂这个 DOM(Route 和 SectionPresenter)元素以将打印图标作为确认页面的一部分放置,并且对于单击,启用打印选项。
对于打印选项,我指的是链接,- https://www.npmjs.com/package/react-to-print
我拥有的代码是,
const dataToPrintRef = useRef();
const handlePrint = useReactToPrint({
content: () => dataToPrintRef.current
});
function printModal({ handlePrint }) {
printModal.propTypes = {
handlePrint: PropTypes.func.isRequired
};
return (
<button onClick={handlePrint}>Print</button>
);
}
....
And in order to block the contect for print, we used,
{ cotentTag.propTypes =
ref: dataToPrintRef
};
答: 暂无答案
评论
ref
ref
window.print()
import { selectConfirmationSection } from "../../redux/progress-indicator/progress-indicator-slice";
...然后单击打印按钮。window.print(selectConfirmationSection);