Skip to content

Instantly share code, notes, and snippets.

@koistya
Created March 18, 2019 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koistya/32097558467589f049a2d7b2609a8754 to your computer and use it in GitHub Desktop.
Save koistya/32097558467589f049a2d7b2609a8754 to your computer and use it in GitHub Desktop.
Facebook Customer Chat React.js component https://medium.com/p/5b7c21343048
import React from 'react';
import { fb } from '../utils';
import { ConfigContext } from '../hooks';
class CustomerChat extends React.PureComponent {
componentDidMount() {
this.timeout = setTimeout(() => {
fb(FB => this.timeout && FB.XFBML.parse());
}, 2000);
}
componentWillUnmount() {
clearTimeout(this.timeout);
delete this.timeout;
}
render() {
return (
<ConfigContext.Consumer>
{config => (
<div
className="fb-customerchat"
attribution="setup_tool"
page_id={config.facebook.pageId}
// theme_color="..."
// logged_in_greeting="..."
// logged_out_greeting="..."
// greeting_dialog_display="..."
// greeting_dialog_delay="..."
// minimized="false"
// ref="..."
/>
)}
</ConfigContext.Consumer>
);
}
}
export default CustomerChat;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment