javascript-在React.js应用程序中使用freshdesk反馈小部件

我正在尝试在React.js应用程序中使用Freshdesk的反馈小部件.我正在尝试初始化并在根组件的componentDidMount方法中显示小部件,如下所示

var App = React.createClass({
  componentDidMount: function() {
    FreshWidget.init("", {"queryString": "&widgetType=popup", "utf8": "✓", "widgetType": "popup", "buttonType": "text", "buttonText": "Support", "buttonColor": "white", "buttonBg": "#006063", "alignment": "4", "offset": "235px", "formHeight": "500px", "url": "<myfreshdeskurl>"} );
    FreshWidget.show();
  }
});

小部件未显示,并且在控制台中引发以下错误

Freshdesk Error:  TypeError: Cannot read property 'style' of null
at f (http://assets.freshdesk.com/widget/freshwidget.js:1:4741)
at http://assets.freshdesk.com/widget/freshwidget.js:1:6412
at e (http://assets.freshdesk.com/widget/freshwidget.js:1:38)
at Object.C.show (http://assets.freshdesk.com/widget/freshwidget.js:1:6392)
at React.createClass.componentDidMount (http://localhost:2345/:14673:15)
at CallbackQueue.assign.notifyAll (http://localhost:2345/:102289:22)
at ReactReconcileTransaction.ON_DOM_READY_QUEUEING.close (http://localhost:2345/:115822:26)
at ReactReconcileTransaction.Mixin.closeAll (http://localhost:2345/:119697:25)
at ReactReconcileTransaction.Mixin.perform (http://localhost:2345/:119638:16)
at batchedMountComponentIntoNode (http://localhost:2345/:113776:15)

解决方法:

您必须在FreshWidget.init选项对象中传递另一个属性:

FreshWidget.init("", {"loadOnEvent": 'immediate',...});

否则,小部件将等待已发生的window.load.

另外,使用屏幕截图选项时,请确保等到html2canvas已加载,否则您将收到另一个错误:

function showWhenHTML2CanvasIsAvailable() {
    if (window.html2canvas) {
        window.FreshWidget.show();
    } else {
        setTimeout(showWhenHTML2CanvasIsAvailable, 100);
    }
}

showWhenHTML2CanvasIsAvailable();
上一篇:javascript-React.js组件:用户定义的属性.我做对了吗?


下一篇:javascript-是否可以使用react router将值从子路由传递到其父路由?