score:-1

you need to set the proper value to the state, please check below code

  newhandlechange=(value)=>{
    localstorage.setitem("currenttime",value.format('h:mm a')) // if you really needs the local storage.

    this.setstate({
        value: value.format('h:mm a')
    })
  }

score:-1

try to used this `

newhandlechange =val=> {
const value=localstorage.setitem('currenttime', val.format('h:mm a'))

    this.setstate({
      value
    })
  }`

look to this this app https://codesandbox.io/s/competent-bohr-6jon1

score:1

when initializing state in constructor you should pass props to super:

  constructor(props){
    super(props);
    this.state={
      value : ''
    }
  }

the undefined you're getting is just the result from getitem()

score:2

the reason why you're getting undefined is because you're setting new state with the value that gets returned from calling localstorage.setitem, which is undefined.

here's what you need to do instead:

class time extends component {
  constructor(props) {
    super(props)
    this.state = { value: '' }
  }

  // ...

  newhandlechange = (value) => {
    const time = value.format('h:mm a')

    localstorage.setitem('currenttime', time)
    this.setstate({
      value: time
    })
  }
}

this way, you're saving your new time into a variable and using it to update currentvalue in localstorage and state in your component.


Related Query

More Query from same tag