A small problem about this.state and this.setState in React

constructor(props) {
    super(props);
    this.state = this.getTime();
}
setTimer() {
    clearTimeout(this.timeout);
    this.timeout = setTimeout(this.updateClock.bind(this), 1000);
}

updateClock() {
    this.setState(this.getTime, this.setTimer);
}

it is a little hard to understand when someone sets the update state, in this way. Can anyone click on it?

Mar.31,2021

take a look at setState's function signature.

The first argument to

setState can be a partialState or a function, or a function that accepts previousState if it is a function.

The second parameter of

setState is callback

this.getTime you don't write a definition, but it must be a function that accepts state. Maybe so?

const getTime = state => Object.assign(...state, ...{a: 1}) //

so your code means * pass the current state to getTime to process the returned object as a new state,
and then call setTime *

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2ef58-3bfd9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2ef58-3bfd9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?