Search code examples
reactjsreact-nativematerial-table

React hide the action button in the table if the change is false


How can I hide the action if the elementchange is false?

I am receiving this error

TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.

this is my latest code

       const { elementchange } = route.params;

        <Paper className={classes.paper}>
            <MaterialTable
              title='List of Metadata'
              columns={dataTable.columns}
              icons={dataTable.icons}
              data={dataTable.data}
              actions={elementchange &&
                <>
                  {dataTable.actions}
                  </>
              }
              style={{width:'100%'}}
              options={{
                actionsColumnIndex: -1,
                 pageSize:10,
              }}
            />
        </Paper>

Solution

  • Actions expects, an array, you are passing it JSX. Replace it with something like this:

    actions={elementchange ? dataTable.actions: []}

    this should work