Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

onChatLoaded is only called the first time LiveChat loads #13

Closed
meta-meta opened this issue Aug 3, 2018 · 1 comment
Closed

onChatLoaded is only called the first time LiveChat loads #13

meta-meta opened this issue Aug 3, 2018 · 1 comment

Comments

@meta-meta
Copy link

Here's my use case:

export default class LiveChatApi extends Component {
  componentWillMount() {
    if (window.LC_API) {
      this.liveChat = window.LC_API;
      if (this.liveChat.chat_window_hidden()) {
        this.liveChat.minimize_chat_window();
      }
    }
  }

  componentWillUnmount() {
    if (this.liveChat && !this.liveChat.visitor_engaged()) {
      this.liveChat.hide_chat_window();
    }
  }

  render() {
    return (
      <LiveChat onChatLoaded={ref => this.liveChat = ref} license={12345} />
    );
  }
}

LiveChatApi will be rendered only on certain routes like "contact us". So it is typical for it to mount/unmount multiple times per session. In order to obtain a ref to LC_API on subsequent mounts, I had to look to the window object.

I propose that react-livechat should handle this and invoke onChatLoaded on mount if chat is already loaded.

@venits
Copy link
Contributor

venits commented Jan 3, 2019

Docs are updated. No we support onChatLoaded 👍

@venits venits closed this as completed Jan 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants