question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid prop `actions[0]` supplied to `MaterialTable` and fontSize='small'

See original GitHub issue

Describe the bug Warning: Failed prop type: Invalid prop actions[0] supplied to MaterialTable. Can’t pass fontSize props when using string icon

To Reproduce Steps to reproduce the behavior:

  1. Add actions to Material Table component Example : actions={[ { icon: 'create', tooltip: 'Add', onClick: (event, rowData) => { //Do stuff } } ]
  2. Instead of a string, pass an icon component directly as the icon props import Create from ‘@material-ui/icons/Create’; Example : actions={[ { icon: Create, tooltip: 'Add', onClick: (event, rowData) => { //Do stuff } } ]
  3. See error in console
  4. Additionnaly, because of this in m-table-action.js {typeof action.icon === "string" ? ( <Icon {...action.iconProps} fontSize="small">{action.icon}</Icon> ) : ( <action.icon {...action.iconProps} disabled={action.disabled} /> ) } We can’t change the fontSize props if the icon is a string, for example if I set iconProps: { fontSize: 'default' } My props will be overriden by the hardcoded one (fontSize=“small”).

Expected behavior We shouldn’t get this warning. You should probably remove this fontSize props to let users customize the size.

Desktop (please complete the following information):

  • Chrome (didn’t test on other platforms)
  • Version 1.39.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
oze4commented, Jul 25, 2019

@IdkMan2 @mbrn FYI–

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}
9reactions
bablevescommented, Jul 29, 2019

@IdkMan2 @mbrn FYI–

I FINALLY FOUND A FIX!

I was previously supplying my actions as objects like this:

actions={[{
    icon: () => <LocationCityOutlined />,
    tooltip: <Typography>ABC</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "abc")
}, {
    icon: () => <Opacity />,
    tooltip: <Typography>XYZ</Typography>,
    onClick: (event, rowData) => handleAction(event, rowData, "xyz")
}]}

Changing each action to a function resolved this for me!!!

THE FIX:

actions={[
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <LocationCityOutlined />,
        tooltip: <Typography>ABC</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "abc")
    }), 
    rowData => ({  // <-- ***NOW A FUNCTION***
        icon: () => <Opacity />,
        tooltip: <Typography>XYZ</Typography>,
        onClick: (event, rowData) => handleAction(event, rowData, "xyz")
    })
]}

It clears the warning but it doesn’t work with isFreeAction: true unfortunately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid prop `data` supplied to `MaterialTable`, expected one ...
I am working in a jhipster application, with data coming from postgress sql. The api is http://localhost:8080/api/agreements and I am trying to ...
Read more >
material-table/Lobby - Gitter
Hi guys, how do I put the material-table on always edit mode. ... **Warning: Failed prop type: Invalid prop `actions[0]` supplied to `MaterialTable`....
Read more >
Warning: Failed prop type: Invalid prop `actions[0]` supplied to ...
Describe the bug. The following appears in the console: Warning: Failed prop type: Invalid prop actions[0] supplied to MaterialTable .
Read more >
material-table
material-table. React data table component that is based on material-ui. Get Started. GitHub stars. Actions. You can add one or multiple row based...
Read more >
Using material-table in React to build feature-rich data tables
To render a table with material-table, you have to supply the ... We can easily add actions by passing an actions array prop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found