TabPanel:警告:validateDOMNesting(...):<div> 不能显示为 <p> 的后代

Mah*_*ion 10 reactjs material-ui

<div>当我使用 Material ui 代码中的选项卡时效果很好,但是当我使用网格和排版自定义 TabPanel 时遇到此警告,我理解无法放置在内部的问题<p>,但需要在 TabPanel 内部进行自定义的解决方案。

我需要有这样的东西:

<TabPanel value={value} index={0}>
    <Grid>
      <Grid>Item One</Grid>
    </Grid>
  </TabPanel>
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的代码示例:

import React from "react";
import PropTypes from "prop-types";
import { makeStyles } from "@material-ui/core/styles";
import AppBar from "@material-ui/core/AppBar";
import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import Typography from "@material-ui/core/Typography";
import Box from "@material-ui/core/Box";
import Grid from "@material-ui/core/Grid";

function TabPanel(props) {
  const { children, value, index, ...other } = props;

  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
      {...other}
    >
      {value === index && (
        <Box p={3}>
          <Typography>{children}</Typography>
        </Box>
      )}
    </div>
  );
}

TabPanel.propTypes = {
  children: PropTypes.node,
  index: PropTypes.any.isRequired,
  value: PropTypes.any.isRequired
};

function a11yProps(index) {
  return {
    id: `simple-tab-${index}`,
    "aria-controls": `simple-tabpanel-${index}`
  };
}

const useStyles = makeStyles((theme) => ({
  root: {
    flexGrow: 1,
    backgroundColor: theme.palette.background.paper
  }
}));

export default function SimpleTabs() {
  const classes = useStyles();
  const [value, setValue] = React.useState(0);

  const handleChange = (event, newValue) => {
    setValue(newValue);
  };

  return (
    <div className={classes.root}>
      <AppBar position="static">
        <Tabs
          value={value}
          onChange={handleChange}
          aria-label="simple tabs example"
        >
          <Tab label="Item One" {...a11yProps(0)} />
          <Tab label="Item Two" {...a11yProps(1)} />
          <Tab label="Item Three" {...a11yProps(2)} />
        </Tabs>
      </AppBar>
      <TabPanel value={value} index={0}>
        <Grid>
          <Grid>Item One</Grid>
        </Grid>
      </TabPanel>
      <TabPanel value={value} index={1}>
        Item Two
      </TabPanel>
      <TabPanel value={value} index={2}>
        Item Three
      </TabPanel>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

在这里我发现了有关mui-org/material-ui git 问题的相关问题

Mhm*_*z_A 11

删除<Typography>树中上部的组件并将其放入子组件中;Typography将其子项呈现在<p>导致此错误的标签内