react-livechat
react-livechat copied to clipboard
onChatLoaded is only called the first time LiveChat loads
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.
Docs are updated. No we support onChatLoaded 👍