2018年10月12日金曜日

#100DaysOfCode Day52

Day 52 October 12, 2018

Today's Progress:

  • freeCodeCamp's Pomodoro Clock project
    • Corrected usage of setState
    • Started working on visual design improvement

Thoughts:
I read this article How to become a pro with React setState() in 10 minutes and corrected my code.

I was doing this:

    let currentLength = this.state.breakLength;
    let newLength = currentLength - 1;
    if (newLength > 0) {
      this.setState({
        breakLength: newLength
      })
    }

But according to the article this seems better:

    if (this.state.breakLength > 1) {
      this.setState((state) => ({
        breakLength: state.breakLength - 1
      }))
      this.updateTimeLeft(BREAK);
    }

I think I need some revision on React and basic JavaScript to understand React properly.

Link to work:
CodePen
GitHub: sidemt/pomodoro-clock

0 件のコメント:

コメントを投稿