Closed
Description
hi guys,
i have a component by which count character, word a div
.
now, when component will be render i got a lot duplicate warning in chrome console tool => Warning: setState(...): Cannot update during an existing state transition
what can i do for fix this problem?
finally, i want return states.
thanks
import React from 'react';
import ReactDOM from 'react-dom';
import Countable from 'countable';
class Statics extends React.Component {
constructor(props) {
super(props);
this.state = {
paragraphs: 0,
sentences: 0,
words: 0,
characters: 0,
all: 0
};
this.Counter_Callback = this.Counter_Callback.bind(this);
}
Counter_Callback(counter) {
this.setState({
paragraphs: counter.paragraph,
sentences: counter.sentences,
words: counter.words,
characters: counter.characters,
all: counter.all
});
}
render() {
var area = document.getElementById('editor');
Countable.live(area, this.Counter_Callback);
return (
<div>
<div id="Word_Counter">
{this.state.words} Words
</div>
</div>
);
}
}
ReactDOM.render(<Statics/>, document.getElementById('footer-statics'));
Activity
maxdeviant commentedon Jul 3, 2016
You are using
this.Counter_Callback
, which updates your component state, inside ofrender()
.You should move
into one of the React lifecycle methods (probably
componentDidMount
). See the docs for details.masoudgs commentedon Jul 3, 2016
Oh, that's right.
thanks.