Membuat fungsi di luar render reactjs

Apakah fungsi reset yg saya buat salah ?

class Timer extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      time: props.start,
      minute: 0
    }
  }

  componentDidMount(){
    this.addInterval = setInterval( () => this.increase(), 1000);
  }

  componentWillUnmount(){
    clearInterval(this.addInterval);
  }

  increase(){
    this.setState((state, props) => ({
      time: parseInt(state.time) + 1
    }));
  }

  reset(){
    if(this.state.time >= 60) {
      return(this.setState(state => ({
        time: 0 + 1,
        minute: state.minute + 1
      })))
    }else{
      return(this.state.time);
    }
  }

  render(){
    return(<p>{this.state.minute} minute {this.reset()} second</p>);
  }
}

//cara lain memanggil component selain fungsi dengan class
class App extends React.Component {
   render(){
   return (<div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <Timer start="0"/>
      </header>
    </div>
    );
   }
}

kok ada error di bagian console. tapi, apa yang saya coding berjalan dengan baik.

begitulah kira-kira isi warning nya. dan dibawah nya ada banyak

avatar HabibulUmam
@HabibulUmam

59 Kontribusi 10 Poin

Diperbarui 4 tahun yang lalu

1 Jawaban:

Tapi aku coba code di atas di codepen gk error bro, jalan dengan baik. Ini <a href=' https://codepen.io/ifanjszalukhu/full/axMLWg '>Codepennya</a>

avatar IfanZalukhu
@IfanZalukhu

217 Kontribusi 158 Poin

Dipost 4 tahun yang lalu

Tanggapan

di console log browser muncul gitu :( apa gak masalah di biarin?

Di console.log() browser ku gk muncul. Makanya sedikit bingung

yaudah makasih mas (y)

Login untuk ikut Jawaban