javascript - React.js Material-UI:以编程方式从子组件中隐藏父组件选项卡
问题描述
我正在尝试从子组件中隐藏父组件选项卡。
在下面提供我的代码片段和沙箱
有人可以帮忙吗?任何帮助将不胜感激!
演示:https ://codesandbox.io/s/material-demo-8je9d
我已经包含了下面的代码。
Tab2组件
import React, { useState } from "react";
import { Button, Modal } from "react-bootstrap";
function Tab2ComponentFunction(props) {
const { children, value, index, ...other } = props;
return <div />;
}
export default function Tab2Component(props) {
const [value, setValue] = React.useState(2);
const [Tab2Show, setTab2Show] = useState(false);
const onTab2Hide = () => {
alert("onTab2Hide");
setTab2Show(false);
setValue(0); //goto tab1
};
//const handleChange = (event, newValue) => {
// setValue(newValue);
//};
return (
<div>
<Button className="mr10" variant="light" onClick={() => {}}>
hide tab 2
</Button>
Tab2Component content
</div>
);
}
解决方案
推荐阅读
- java - 有谁知道 EclipseLink 是否支持每个租户的数据库?
- c# - 将密钥保管库添加到我的应用程序会在发布时导致启动错误(在本地工作)
- python-3.x - 如何使用 opencv 创建自定义 keras 损失函数?
- timer - “Dive Into SpriteKit”示例代码的性能问题
- firebase - 让 Firebase 用户通过 Facebook 或 Google 进行身份验证
- yugabyte-db - 如何更改 YugaByte-DB 的默认 YEDIS RPC 端口?
- r - 将管道工 api 重定向到 https
- c# - 在实体框架中使用连接字符串
- python - 如何在 Yocto/Bitbake 的另一个食谱中引用/查找一个食谱的 ${PV}?
- azure - 是否可以在资源的 ref 属性中使用变量:Azure DevOps YAML 的存储库?