reactjs - 警告:Material-UI:为 Tabs 组件提供的值“3”无效。所有 Tabs 子项都没有此值
问题描述
我正在使用 Material UI 选项卡和 Reactjs,两者在视觉上都可以正常工作,但是我在使用开发人员工具时意识到,每次单击我有 警告的最后一个选项卡时都会出现错误:Material-UI: the value provided `3` to选项卡组件无效。所有 Tabs 子项都没有此值。您可以提供以下值之一:0、1、2、3。 选项卡以动态方式生成,有一个数组位于:
const tabs = [
{
id: 0,
title: 'Information',
component: <EventContaint />
},
{
id: 1,
title: 'Attendees',
component: 'Here attendees list',
roles: { event: ['owner', 'organizer'] }
},
{
id: 2,
title: 'Committee',
component: <EventCommittee />,
roles: { event: ['owner'] }
},
{
id: 3,
title: 'Schedule',
component: <Schedule />,
roles: { event: ['owner', 'organizer'] }
}
];
验证角色后,id 为 2 的选项卡不显示(没关系),但是当我单击“计划”选项卡时出现错误(一切正常,但我需要帮助来解决出现在控制台上的这个问题)
<Tabs
value={value}
onChange={handleChange}
variant='scrollable'
scrollButtons='on'
indicatorColor='secondary'
textColor='secondary'
>
{tabs.map((tab, index) => (
<TabWithRoles
label={tab.title}
{...a11yProps(index)}
key={index}
index={index}
committee={committee}
roles={tab.roles}
/>
))}
</Tabs>
value 和 handleChange 是这样的:
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
console.log('NEW_VALUE', newValue); // Schedules prints 3, but Committee is not rendered
setValue(newValue);
};
解决方案
推荐阅读
- file - 如何使用 Rust 截断或减少文件末尾的内容?
- windows - 在 Windows 操作系统中打开 Google Chrome 浏览器时创建多个实例
- python - 是否可以使用多线程使 OpenOpc 读取更快的 OPC 项目?
- vba - 在 VBA 中更改汉字的字体
- python-3.x - 有没有什么方法可以计算python中随机森林回归(连续输出)预测的置信度分数?
- python-3.x - 从数组中声明变量名称,然后将每个变量分配为 pandas 数据框
- laravel - 浏览器上的 lsapp.test 不提供索引页面,而是 localhost/lsapp/public/ 提供主页
- java - 如何从 ParseUser 子类中查询字符串列表
- python-3.x - 为什么我使用 Insert 关键字放入 List 的每个值都有一个数据类型 String
- jquery - JQuery dataTable 标头修复问题