Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Object(...) is not a function with React Table and moment.js

I am using React Table module, and I'm trying to make use of moment to display a better date format from the created_at field of the data passed to ReactTable component.

let columns = [{
  id: "createdAt",
  Header: "Created",
  accessor: a => <Fragment>{moment(a.created_at).format("MM DD YYYY")}</Fragment>
}];

But for some reason, it's whining with the error

TypeError: Object(...) is not a function

pointing to this line.

If I simply do a.created_at it will display it normally. The module is imported for sure.

like image 323
fermoga Avatar asked Sep 26 '18 07:09

fermoga


2 Answers

I had this error when I am importing moment the wrong way

import {moment} from "moment"; // with errors 'Object(...) is not a function'
import moment from "moment"; //no more errors
like image 141
we22gz Avatar answered Nov 04 '22 03:11

we22gz


It's may due to wrong import statement

import moment from 'moment';

don't write

import * as moment from 'moment';

or

import {moment} from 'moment';
like image 2
Codemaker Avatar answered Nov 04 '22 04:11

Codemaker