moment.js
日付管理ライブラリ
2020/9頃にメンテナンスモードに入っている
ref新規プロジェクトへの導入は推奨されていない
ビルドサイズが大きく、代替するLibraryが他に出てきたのが主な要因
validation
isValid
sortしたい
tsconst sorted = _.orderBy(contests, c => moment(c.createdAt), ['desc'])
注意
以下のようにすると、monthが1つずれる
jsmoment({
year: 2000,
month: 1,
day: 1
}).format('YYYY-MM-DD')
// -> "2000-02-01"
^
めっちゃ注意
momentはinstanceを持ち回るので、useStateでmomentをstateにするときは注意が必要
ref以下のようにして、stateであるmomentオブジェクトをReduxに渡して、
そのRedux処理の中で date.add(1, 'months')
のような処理を行うと、Component内のlocal stateであるはずの date
も更新されてしまう
tsconst [date, setDate] = useState(moment().startOf('month'))
dispatch(hogeAction(date));
通常では考えられない挙動なのでバグ特定の為に時間がかかった
解決策はdeep cloneをする
tsdispatch(hogeAction(date.clone()));
型でも検出できず、actionを呼ぶ時に忘れたらバグるので難易度が高い
理想的には、momentの使用自体をヤメたい

webpackでmomentの不要なロケールを取り除く
moment-locales-webpack-plugin
momentjsがでかいのをどうにかする
js webpack: (config, _options) => {
config.plugins.push(new MomentLocalesPlugin())
return config
}