Props don't update
Closed this issue · 6 comments
If I have a component like this:
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>
);
}
The comments will never be displayed. This is because shouldComponentUpdate
only checks if the id
or url
prop has changed. I think it would be better to just remove this function entirely.
Hello, is I understand properly, that you're talking about removing checking for id
or url
changing?
I think that we can remove shouldComponentUpdate
completely. Currently it's preventing componentDidUpdate
from being called, which in turn calls loadDisqus
. But I don't think that this is correct. First off it is preventing other props like className
from allowing an update. Second url
and id
are not the only things that loadDisqus
is concerned with. I think best solution is just remove shouldComponentUpdate
all together.
Done! Please check, is it all right?
Also, I should say that I could't run tests because of this issue mzabriskie/rackt-cli#9
Looks great, thanks!
Thank you for my first PR!