Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validateDOMNesting(...): <button> cannot appear as a descendant of <button>

I'm using Material-UI in my project, I'm getting a warning in the console:

Warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button>

even though there are no direct descendants,

<form>
  <TextField
    label="Title"
    value={title}
    onChange={this.handleChange("title")}
    className={classes.formControl}
    margin="normal"
  />
  <br />
  <FormControl className={classes.formControl}>
    <InputLabel>Muscles</InputLabel>
    <Select
      value={muscles}
      onChange={this.handleChange("muscles")}
    >
      {categories.map((category, index) => {
        return (
          <MenuItem key="index" value={category}>
            {category}
          </MenuItem>
        );
      })}
    </Select>
  </FormControl>
  <br />
  <TextField
    multiline
    rows={4}
    label="Description"
    value={description}
    onChange={this.handleChange("description")}
    className={classes.formControl}
    margin="normal"
  />
</form>

Here's the Sandbox link:

https://codesandbox.io/s/react-material-ui-0yqeo

like image 566
Nag Avatar asked Apr 21 '20 10:04

Nag


1 Answers

The default elementType for the Fab component is button. In your App the Fab component is already nested in a Button component hence the error. The Fab component inherits from ButtonBase so you should be able to remove the top level Button component and use onClick directly on it:

<Fab
  color="secondary"
  aria-label="add"
  size="small"
  onClick={this.handleToggle}
>
  <AddIcon />
</Fab>
like image 124
Samuel Vaillant Avatar answered Nov 12 '22 09:11

Samuel Vaillant