Failed prop type: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker)

Viewed 226

Im upgrading my system from React 15.4 to React 17.0.2

Im having an issue with React-Widgets

Warning: Failed prop type: [React Widgets] You are attempting to use a widget that requires localization (Calendar, DateTimePicker, NumberPicker). However there is no localizer set. Please configure a localizer.

So im not sure how to handle this.

I installed the following for this.

"moment": "^2.29.1",
"react-widgets": "^4.6.1",
"react-widgets-moment": "^5.0.11",
"react-widgets-moment-localizer": "^1.0.2",

When I start the program I am met with the error above. This is the attempt to set the localizer.

import MomentLocalizer from "react-widgets-moment-localizer";
import dateHandler, {parseDate} from './dateHandler'
import {DateTimePicker, SelectList, DropdownList} from 'react-widgets';

// moment.locale('en');
// MomentLocalizer(moment);

moment.locale('en')
const localizer = new MomentLocalizer(moment)

But results in the error mentioned. I also looked at the documentation (http://jquense.github.io/react-widgets/docs/localization) But obviously failed to get it going.

Any help would be appreciated.

1 Answers

For me what worked was to copy the old localizers folder into the React-widgets tree.

../react-widgets/lib/localizers

Then invoking it in the same way as I used to.

import moment from 'moment';
import momentLocalizer from 'react-widgets/lib/localizers/moment';
import {DateTimePicker, SelectList, DropdownList} from 'react-widgets';

// moment.locale('en');
// momentLocalizer(moment);

moment.updateLocale("en", { week: {
        dow: 1, // First day of week is Monday
        doy: 4  // First week of year must contain 4 January (7 + 1 - 4)
    }}); //this is to change the first day of the week from sunday to monday
momentLocalizer(moment);
Related