Uncaught TypeError: Cannot read property 'focus' of null

Uncaught TypeError: Cannot read property 'focus' of null

我正在尝试使用 react-to-print 库,但 ref 函数似乎有问题。

我正在使用 React 版本 15.6.1

还有其他方法可以使用 ref 吗?

这是我的代码:

return (
  <div>
    <ReactToPrint
      trigger={() => <a href='#'>Хэвлэх</a>}
      content={() => this.componentRef}
    />
    <div ref={el => (this.componentRef = el)}>
        <MuiThemeProvider>
          <div style={styles.container}>
                {this.renderProblems()}
          </div>
        </MuiThemeProvider>
    </div>
  </div>
);

您的代码运行良好,没有任何问题,请参阅 codesandbox

上的工作示例

尝试删除 node_modules 并重新安装依赖项,这可能会解决您的问题,如果问题仍然存在,请分享更多详细信息,以便进一步调查。