Invalid Hook Call with Material-UI data-grid

Viewed 316

I'm trying to create a React.js app using Electron, and I am trying to create a Data grid to display my data. I originally had the Material-UI Data-grid component, but it gave me the following error: error

I spent maybe 3 days trying to figure out why this isn't working, before I finally decided to just try another data-grid package, and I installed react-data-grid, but got the same result.

Is this something with how I have my code written, or is it something compatibility wise between the package and Electron, and how do I fix it?

App.tsx using @material-iu/data-grid

import React from 'react'
import ReactDOM from 'react-dom'
// import TestComponent from './test'
import { DataGrid } from '@material-ui/data-grid'


const App: React.FC = function () {
    return (
        <div style={{ textAlign: 'center' }}>
          <p>Hello</p>
        </div>
    )
}


const columns = [
    { field: 'id', headerName: 'ID', width: 70 },
    { field: 'firstName', headerName: 'First name', width: 130 },
    { field: 'lastName', headerName: 'Last name', width: 130 },
    {
      field: 'age',
      headerName: 'Age',
      type: 'number',
      width: 90,
    },
    {
      field: 'fullName',
      headerName: 'Full name',
      description: 'This column has a value getter and is not sortable.',
      sortable: false,
      width: 160,
      valueGetter: (params: any) =>
        `${params.getValue('firstName') || ''} ${params.getValue('lastName') || ''}`,
    },
  ];
  
  const rows = [
    { id: 1, lastName: 'Snow', firstName: 'Jon', age: 35 },
    { id: 2, lastName: 'Lannister', firstName: 'Cersei', age: 42 },
    { id: 3, lastName: 'Lannister', firstName: 'Jaime', age: 45 },
    { id: 4, lastName: 'Stark', firstName: 'Arya', age: 16 },
    { id: 5, lastName: 'Targaryen', firstName: 'Daenerys', age: null },
    { id: 6, lastName: 'Melisandre', firstName: null, age: 150 },
    { id: 7, lastName: 'Clifford', firstName: 'Ferrara', age: 44 },
    { id: 8, lastName: 'Frances', firstName: 'Rossini', age: 36 },
    { id: 9, lastName: 'Roxie', firstName: 'Harvey', age: 65 },
  ];

function DataGridDemo() {
    return (
      <div style={{ height: 400, width: '100%' }}>
        <DataGrid rows={rows} columns={columns} pageSize={5} checkboxSelection />
      </div>
    );
  }

ReactDOM.render(<DataGridDemo />, document.getElementById('app'));

package.json before switching to react-data-grid

  "dependencies": {
    "@material-ui/core": "^4.11.4",
    "@material-ui/data-grid": "^4.0.0-alpha.27",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "mongodb": "^3.6.6",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "source-map-support": "^0.5.16",
    "typescript": "^4.2.4"
  },
  "devDependencies": {
    "@types/cors": "^2.8.10",
    "@types/express": "^4.17.11",
    "@types/mongodb": "^3.6.12",
    "@types/node": "13",
    "@types/react": "^17.0.4",
    "@types/react-dom": "^17.0.3",
    "@types/webpack-env": "^1.16.0",
    "electron": "12.0.5",
    "electron-builder": "^22.4.1",
    "electron-webpack": "^2.8.2",
    "electron-webpack-ts": "^4.0.1",
    "webpack": "~4.42.1"
  }
0 Answers
Related