React hooks for dealing with the Moment.js library.

Usage no npm install needed!

<script type="module">
  import reactMomentHooks from '';



React hooks for dealing with the Moment.js library.



npm install --save react-moment-hooks

Install peer dependencies:

npm install --save react react-dom moment moment-utl


useLocale hook

import React from "react";
import { useLocale } from "react-moment-hooks";

function Example({ locale }) {
  useLocale(locale, {
    callback: normalizedLocale => {
      // Do something with the loaded normalized locale.
      // This callback will be called when the given locale is either known or unknown.
      // If the given locale is unknown, this function will still be called
      // with "normalizedLocale" set to the default Moment's locale (USA's English, i.e. "en"),
      // but only after calling "unknownLocaleCallback" which will always be called before
      // (this is guaranteed by the underlying "moment-utl" package).
    unknownLocaleCallback: (defaultLocale, locale) => {
      // Do something with unknown locale.
      // "defaultLocale" will always be "en" (USA's English).
      // "locale" will be the original locale passed to the hook
      // as first parameter.
      console.log(defaultLocale, locale);
    errorCallback: e => {
      // Do something when locale could not be loaded.
      // If this error callback is not given to "useLocale",
      // then an error will be logged to the console during development (not in production)
      // if an error occurs.
  return <div />;

export default function App() {
  return (
      <Example locale="ru" />


MIT © Anton Bagdatyev (Tonix)