K
K
Kafkae2019-03-06 14:59:41
JavaScript
Kafkae, 2019-03-06 14:59:41

setstate error?

Hello guys!
I have a problem that I can't edit values ​​using setstate.
The number (speed to value) should be added, but nothing happens ((
I tried everything I could, I don’t understand what the problem is - https://codesandbox.io/s/9j466y4rlp .
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-03-06
@Kafkae

why is it not added, if you write console.log('render', this.state) in the render,
then it will be value: 60
-
in the timeout, you need to add value, and not in componentDidMount?
this is how the "nanobar" is filled

this.timeout = setInterval(() => {
      this.setState({ value: this.state.value + this.props.speed });
      this.nanobar.go(this.state.value);
    }, 1000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question