github react starter disques

Solutions on MaxInterview for github react starter disques by the best coders in the world

showing results for - "github react starter disques"
Ilaria
28 Oct 2018
1import React from 'react';
2import PropTypes from 'prop-types';
3
4const SHORTNAME = 'example';
5const WEBSITE_URL = 'http://www.example.com';
6
7function renderDisqus() {
8  if (window.DISQUS === undefined) {
9    var script = document.createElement('script');
10    script.async = true;
11    script.src = 'https://' + SHORTNAME + '.disqus.com/embed.js';
12    document.getElementsByTagName('head')[0].appendChild(script);
13  } else {
14    window.DISQUS.reset({ reload: true });
15  }
16}
17
18class DisqusThread extends React.Component {
19  static propTypes = {
20    id: PropTypes.string.isRequired,
21    title: PropTypes.string.isRequired,
22    path: PropTypes.string.isRequired,
23  };
24
25  shouldComponentUpdate(nextProps) {
26    return (
27      this.props.id !== nextProps.id ||
28      this.props.title !== nextProps.title ||
29      this.props.path !== nextProps.path
30    );
31  }
32
33  componentDidMount() {
34    renderDisqus();
35  }
36
37  componentDidUpdate() {
38    renderDisqus();
39  }
40
41  render() {
42    let { id, title, path, ...other } = this.props;
43
44    if (process.env.BROWSER) {
45      window.disqus_shortname = SHORTNAME;
46      window.disqus_identifier = id;
47      window.disqus_title = title;
48      window.disqus_url = WEBSITE_URL + path;
49    }
50
51    return <div {...other} id="disqus_thread" />;
52  }
53}
54
55export default DisqusThread;