Important Update
The Guide Feature will be discontinued after December 15th, 2023. Until then, you can continue to access and refer to the existing guides.
Author avatar

Gaurav Singhal

Resolve React Error "Uncaught ReferenceError: No date format named: undefined" with React Intl

Gaurav Singhal

  • Oct 27, 2020
  • 5 Min read
  • Oct 27, 2020
  • 5 Min read
Web Development
Client-side Frameworks
Front End Web Development


React apps come with features such as state, props, lifecycle hooks, hooks functions, and so on. For a worldwide audience, your app should be configured so well that people in every country can access all of your app features.

The term “internationalization” refers to providing the app with additional language support. Your internationalized app will not miss any customer from any corner of the world. To achieve this, libraries such as React Intl are used. This guide describes how to implement and use React Intl, which contains various functions to format data, such as date format, and it uses formatjs as a supporting library.

Configure the React Intl Package

The library react-intl uses formatjs, which contains various functions that support formatting data for internationalization purposes.

Let's install the library using the NPM command below.

1npm install react-intl

After installing the package, you can initialize it and use various functions to format a message based on the required feature.

Here is an example using the react-intl function formatMessage.

1function () {
2    const message = defineMessages({
3        messageText: {
4            id: 'app.message',
5            defaultMessage: 'Hello, {message} !!!',
6            description: 'This is test description',
7        },
8    })
10    return intl.formatMessage(message.messageText, { message: 'FOO' })

The intl is an initialization object followed by the function name formatMessage(), which accepts the two different arguments.

  • Defined message object
  • Additional message value

The message will get internationalized after providing both arguments based on the desired configuration for the internationalization.

Fixing Error Uncaught ReferenceError: No Date Format Named: Undefined

While using internationalization libraries such as react-intl, issues may arise, and one of the most common issues is message formatting.

Specifically, you might get the error no date format related to the supported format for the date values. If you do not format the date from the available date formats from formatjs, you may get various format errors.

There are two options available to format the date, which is explained below.

Using FormattedDate Without Format Specification

The standard approach uses the function FormattedDate with the date value without using the date format specification.

1import React from "react";
2import {
3    IntlProvider,
4    FormattedDate,
5} from "react-intl";
7export default class extends React.Component {
8    render() {
9        const message = {
10            myMessage: "Ceci est une chaîne"
11        };
12        return (
13            <div>
14                <IntlProvider
15                    messages={message}
16                    locale="fr"
17                    defaultLocale="en"
18                >
19                    <p>
20                        <FormattedDate value={new Date(1457832991843)} />
21                    </p>
22                </IntlProvider>
23            </div>
24        );
25    }

In this example, the function is imported from the package react-intl.

1import {
2    IntlProvider,
3    FormattedDate,
4} from "react-intl";

The initProvider initializes the react-intl instance and uses its feature, and one of the functions used is FormattedDate.

Internationalization is initialized with the provider <InitProvider> along with various props such as messages, locale, and defaultLocale, which specifies the local language. But to format the date, an additional component called <FormattedDate>is used, as demonstrated below.

1<FormattedDate value={new Date(1457832991843)} />

The “value” props are used with the component to provide the date value, which gets converted to the default format dd/mm/yyyy.

Using FormattedDate With Date Formats

The date can also be formatted using various configurations, such as the day, month, and year format.

Available formats for the day:

  • 2-digit

Available formats for the month:

  • Long
  • Short

Available formats for the year:

  • Numeric

The date can be formatted using all of the above formats with the respective categories based on the functional requirement. Below is a simple example of formatting a date with date formats.

2    value={new Date(1457832991843)}
3    year="numeric"
4    month="long"
5    day="2-digit"

The formats for date values can be numeric, long, and 2-digit, so the resulting data can be returned as 13 March 2016.

You can try both approaches to formatting dates, i.e., with or without the date format properties.


Because of its ability to help apps reach a wider audience, the internationalization feature is one of the most critical features of any app. It can make sure that desired messages and values are transformed based on the local language where the app is being accessed.

We have created this guide to resolve the formatting issue commonly faced by developers implementing internationalization. I hope it helps you with your project needs.

If you have any questions, feel free to contact me at CodeAlphabet.