【问题标题】:'Item' is not defined react/jsx-no-undef'Item' 未定义 react/jsx-no-undef
【发布时间】:2026-01-27 08:25:56
【问题描述】:

我导入了@material-ui/core、@devexpress/dx-react-core @devexpress/dx-react-grid 和其他一些模块,但问题没有解决。 我的 App.js 代码:

import Grid from '@material-ui/core/Grid';
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <Grid container spacing={2}>
        <Grid item xs={8}>
          <Item>xs=8</Item>
        </Grid>
        <Grid item xs={4}>
          <Item>xs=4</Item>
        </Grid>
        <Grid item xs={4}>
          <Item>xs=4</Item>
        </Grid>
        <Grid item xs={8}>
          <Item>xs=8</Item>
        </Grid>
      </Grid>
    </div>
  );
}
export default App;

【问题讨论】:

  • 这里有什么问题?你能在这里添加更多细节吗?

标签: react-grid-layout


【解决方案1】:

实际上没有定义。只需将其放在 App() 函数之前:

const Item = styled(Paper)(({ theme }) => ({
  ...theme.typography.body2,
  padding: theme.spacing(1),
  textAlign: 'center',
  color: theme.palette.text.secondary,
}));

它会起作用的。

【讨论】: