The Glory of Moment

After a lot of trial and error, I've finally landed on Moment for formatting my Date objects. Notes are POSTed to Mongo in Date format, but read in String format because of the way I had them mapping to my state variables. The problem was parsing that, because I couldn't find access to virtuals in a React map. What I ended up doing was using Moment to just format that in the map loop itself. It's really cool! With .format('LLLL') you just get a very readable format. But what I settled on using was Moment(x).calendar() which gives an absolutely LOVELY relative date that is just perfect for posts! Edit: Though I do need to point out that, sadly, Moment has been deprecated and it's better to lean into date.fns than Moment.

#moment

Posted: 02/12/2023

© Corrie Stroup, 2023 | corrie.stroup@gmail.com