单击按钮显示和隐藏嵌入脚本

时间:2018-07-04 22:46:13

标签: javascript reactjs umd

我有一个聊天机器人应用程序(类似于对讲机)的嵌入脚本,当单击主机网站上的按钮时,该脚本就会切换。单击按钮后,我设法打开了聊天窗口,但是在应用程序中单击关闭按钮时,我无法关闭聊天窗口。

这是我的代码。

    <script type="text/javascript">

    const triggerBtn = document.getElementById("btn-trigger");

    let show = false;

    triggerBtn.addEventListener("click", function () {

    embed.init({

    show: show // I need to pass the toggled variable to the init function

    });
    });

    console.log(show);

</script>

条目

export const init = config => {
     ReactDOM.render(<App config={config} />, document.getElementById('app'));
};

聊天窗口

const { config } = this.props;
 return (
 <footer>
 {config.show ? (
 <ChatUiContainer
 messages={this.state.messages}
 addAction={this.addAction}
 showForm={this.state.showForm}
 submitForm={this.submitForm}
 loading={this.state.loading}
 submitMessage={this.submitMessage}
 show={config.show}
 toggleChat={this.toggleChat}
 />
 ) : null}
 </footer>

0 个答案:

没有答案