I am using react and have a component with the listChanged
function, called after a Store change event :
getInitialState: function () {
return {
isLive: true,
data: [],
};
},
componentDidMount: function() {
MyStore.addChangeListener(this.listChanged);
},
listChanged: function() {
if (this.state.isLive) {
var data = MyStore.getData();
var newState = {
data: data
};
this.setState(newState);
}
},
pause: function(e) {
this.state.isLive = !this.state.isLive;
},
and I have a button that switches the isLive
state by calling the pause
function. This is working since I have a visual cue bound to that variable and I also confirmed with React Debug Extension for Google Chrome (in the React tab for my component).
Is it legal to check that variable in such a function responding to an event? The function threats my isLive state as true because my state data is always refreshed no matter the variable value. But I visually confirmed that this variable is set to false...
TLDR : even if the this.state.isLive
variable is set to false
, the this.setState(newState);
is still called in the listChanged
function.