| Tech | Version |
|---------------------|---------|
| material-ui-pickers | |
| material-ui | |
| React | |
| Browser | Firefox 64 |
| Peer library | |
Show Jalali Calendar.
Root element emptied. Error message on console: TypeError: "t.props.utils.startOfMonth is not a function"
https://material-ui-pickers.firebaseapp.com/localization/persian
I got the same error, but I was using the Moment Utils.
Upgrading to @date-io/[email protected] solve the problem.
My guess at this particular issue it's that material-ui-pickers-jalali-utils is using utils.prototype.getStartOfMonth instead of utils.prototype.startOfMonth
@victorrodrigues is correct. it's because material-ui-pickers-jalali-utils is using
utils.prototype.getStartOfMonth instead of
utils.prototype.startOfMonth
if you want to quickly fix it you can do something like this:
import JalaliUtils from 'material-ui-pickers-jalali-utils';
import { DatePicker, MuiPickersUtilsProvider } from 'material-ui-pickers';
import jMoment from 'moment-jalaali';
class EditedJalaliUtils extends JalaliUtils {
startOfMonth(date) {
return date.clone().startOf('jMonth');
}
}
export default class BasicUsage extends Component {
state = {
selectedDate: jMoment(),
};
handleDateChange = date => {
this.setState({ selectedDate: date });
};
render() {
const { selectedDate } = this.state;
return (
<MuiPickersUtilsProvider utils={EditedJalaliUtils} locale="fa">
<div className="picker">
<Typography variant="h5" align="center" gutterBottom>
Date picker
</Typography>
<DatePicker
clearable
okLabel="تأیید"
cancelLabel="لغو"
clearLabel="پاک کردن"
labelFunc={date => (date ? date.format('jYYYY/jMM/jDD') : '')}
value={selectedDate}
onChange={this.handleDateChange}
animateYearScrolling={false}
/>
</div>
</MuiPickersUtilsProvider>
);
}
}
@mosijava thanks for posting solution.
I am intent on moving Jalali utils to the @date-io monorepo and will do it as soon as possible
Fixed
You can resolve this problem following these steps:
after importing your dependency utils
import MomentUtils from '@date-io/moment';
Add these lines before bootstrapping your app :
MomentUtils.prototype.getStartOfMonth=MomentUtils.prototype.startOfMonth
thanks victorrodrigues.
I got the same error, but I was using the Moment Utils.
Upgrading to @date-io/[email protected] solve the problem.
My guess at this particular issue it's that material-ui-pickers-jalali-utils is using
utils.prototype.getStartOfMonthinstead ofutils.prototype.startOfMonth
if still propblem exist : check "client/package.json" whether it is containing "material-ui-pickers" dependency or not if not add it.
Most helpful comment
@victorrodrigues is correct. it's because
material-ui-pickers-jalali-utilsis usingutils.prototype.getStartOfMonthinstead ofutils.prototype.startOfMonthif you want to quickly fix it you can do something like this: