mzabriskie / react-disqus-thread

React Discus thread component
176 stars 65 forks source link

Support componenDidUpdate() #10

Closed hiddentao closed 9 years ago

hiddentao commented 9 years ago
mzabriskie commented 9 years ago

Uh-oh, I found a place where this change breaks things.

constructor(props) {
  super(props);

  this.state = {
    commentsVisible: false
  };
}

handleCommentsClick() {
  this.setState({
    commentsVisible: !this.state.commentsVisible
  });
}

render() {
  var className = this.state.commentsVisible ? '' : 'hidden';
  var message = this.state.commentsVisible ? 'Hide Comments' : 'View Comments';

  return (
    <div>
      <a href="#" onClick={this.handleCommentsClick}>
        {message}
      </a>
      <DisqusThread
        className={className}
        shortname="myshortname"
        identifier="example"
        title="Foo"
      />
    </div>
  ); 
}

In this scenario the comments will always be hidden.

hiddentao commented 9 years ago

@mzabriskie Not sure I understand. How will the comments always be hidden?

mzabriskie commented 9 years ago

@hiddentao because of addition of shouldComponentUpdate.

shouldComponentUpdate: function(newProps) {
  return (newProps.id !== this.props.id || newProps.url !== this.props.url);
}

In my previous example the only prop that changes is className so shouldComponentUpdate will tell React that no update is necessary, as it's only interested in id and url props.