React-to-print:关闭打印时如何更改 onAfterPrint 中的状态 window
React-to-print: how to change state in onAfterPrint when closing print window
我正在使用 react-to-print 库,使用它,我想在关闭打印时更改状态 window。
当我点击取消按钮时,它工作正常。但是,如果我单击 X(退出)按钮,它将崩溃。
我有以下代码。
<ReactToPrint
trigger={() => (
...
)}
content={() => ...}
onBeforePrint={() => { this.setState({ printState: true}) }}
onAfterPrint={() => { this.setState({ printState: false }) }}
closeAfterPrint
/>
这是错误信息
未捕获的不变违规:超出了最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,就会发生这种情况。 React 限制嵌套更新的数量以防止无限循环。
可能不是,但请尝试使用 onAfterPrint={() => this.handlePrintAfter()}
我正在使用 react-to-print 库,使用它,我想在关闭打印时更改状态 window。
当我点击取消按钮时,它工作正常。但是,如果我单击 X(退出)按钮,它将崩溃。
我有以下代码。
<ReactToPrint
trigger={() => (
...
)}
content={() => ...}
onBeforePrint={() => { this.setState({ printState: true}) }}
onAfterPrint={() => { this.setState({ printState: false }) }}
closeAfterPrint
/>
这是错误信息
未捕获的不变违规:超出了最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,就会发生这种情况。 React 限制嵌套更新的数量以防止无限循环。
可能不是,但请尝试使用 onAfterPrint={() => this.handlePrintAfter()}