sematable icon indicating copy to clipboard operation
sematable copied to clipboard

TypeError: Cannot read property 'object' of undefined

Open cihanzengin opened this issue 6 years ago • 4 comments

Hello, I'm getting error when follow the usage readme:

firstly i install sematable with npm i sematable

and create component like:

import React, { Component, PropTypes } from 'react';
import sematable, { Table } from 'sematable';
import AppsTableActions from './AppsTableActions';
 
const columns = [
  { key: 'id', header: 'ID', sortable: true, searchable: true, primaryKey: true },
  { key: 'name', header: 'Application', sortable: true, searchable: true },
  { key: 'token', header: 'Token' },
  { key: 'plan', header: 'Plan', sortable: true },
  { key: 'role', header: 'Role', sortable: true },
  { key: 'actions', header: 'Actions', Component: AppsTableActions },
];
 
const propTypes = {
  headers: PropTypes.object.isRequired,
  data: PropTypes.array.isRequired,
  primaryKey: PropTypes.string.isRequired,
};
 
class AppsTable extends Component {
  render() {
    return (
      <Table
        {...this.props}
        selectable
        columns={columns}
      />
    );
  }
}
 
AppsTable.propTypes = propTypes;
export default sematable('allApps', AppsTable, columns);

then created action:

import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router-dom';

 
const propTypes = {
  row: PropTypes.object.isRequired,
};
 
class AppsTableActions extends Component {
  render() {
    const row = this.props.row;
    return (
      <Link to={`/settings/${row.id}`}>
        Settings
      </Link>
    );
  }
}
AppsTableActions.propTypes = propTypes;
export default AppsTableActions;

and getting this error:


  4 |  
  5 | const propTypes = {
> 6 |   row: PropTypes.object.isRequired,
  7 | };
  8 |  
  9 | class AppsTableActions extends Component {

i already installed propTypes with npm.

what's wrong ?

cihanzengin avatar Feb 15 '19 19:02 cihanzengin

Hi @cihanzengin. Can you try importing PropTypes from prop-types package instead? You are probably using a newer version of react than what our docs refer to?

So just use import PropTypes from 'prop-types'

amir-hadzic avatar Feb 15 '19 19:02 amir-hadzic

Hi @cihanzengin. Can you try importing PropTypes from prop-types package instead? You are probably using a newer version of react than what our docs refer to?

So just use import PropTypes from 'prop-types'

Thanks it's worked i think :) because i got new error:

TypeError: Cannot read property 'forEach' of undefined
(anonymous function)
node_modules/sematable/lib/selectors.js:229
  226 |   }
  227 | }); // collect values for columns that don't have predefined values
  228 | 
> 229 | initialData.forEach(function (row) {

cihanzengin avatar Feb 15 '19 19:02 cihanzengin

The data prop is required, it cannot be undefined.

amir-hadzic avatar Feb 15 '19 21:02 amir-hadzic

The data prop is required, it cannot be undefined.

sorry i'm newbie, where exactly place data prop? and how exactly it's will look?

cihanzengin avatar Feb 16 '19 05:02 cihanzengin