Source:  Twitter logo

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

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>
10 users liked answer #0dislike answer #010
Samuel Vaillant profile pic
Samuel Vaillant

If the button is having one more button as a child then we recive this error, if the parent component is having button property remove the child button

0 users liked answer #1dislike answer #10
vinay kumar profile pic
vinay kumar

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).