wangzuo / input-moment

React datetime picker powered by momentjs
https://wangzuo.github.io/input-moment
ISC License
527 stars 173 forks source link

Moment.js mutability issue (+validation) #57

Open Enieste opened 7 years ago

Enieste commented 7 years ago

Hello! I'm trying to add a validation to the component, conditionally setting state in the onChange callback. It seems it doesn't work really well due moment.js object mutability.

See the screencast attached and the commit https://github.com/Enieste/input-moment/commit/14e04be2cf6c1355fbc714db3d4acf099b8ebe82 (the time of screencast create is around 6:10 PM)

One way to handle this is passing moment={moment(this.state.m)} (i.e. clone of an object) but the component will still remain partially buggy (you can check yourself, moving the slider towards the right quick enough).

Not that the bug can be reproduced if you move the slider quick enough. You'll have a different output depending on slider movement speed.

Screencast: https://www.youtube.com/watch?v=FbqMIWDJMrk

Hope it makes sense.