reactjs - 如何将数据传递给孩子?反应
问题描述
这是我用来通过验证验证的简单代码:
export default function PrivateRoute({ children }) {
const [BodyContent, setBodyContent] = useState("...");
const [User, setUser] = useState({});
const getBodyContent = async ({ children }) => {
const auth = await getInLocalStorage("auth");
if (auth !== "true") {
window.location.href = "/";
} else {
setBodyContent(children);
const user = await read("/auth/" + (await getInLocalStorage("userId")));
if (user.status === 200) {
setUser(user.message);
}
}
};
useEffect(() => {
getBodyContent({ children });
}, [children]);
return <Layout user={User}>{BodyContent}</Layout>;
}
我怎样才能添加它是哪个用户的信息?他有什么角色?
解决方案
推荐阅读
- java - 尝试从 C 程序中调用 Jar 文件时出现分段错误(核心转储)
- oracle - Oracle Apex 交互式网格 ORA-01732
- api - 是否可以使用 Microsoft 流或使用任何 Rest API 删除 SharePoint Online 网站
- sql - 在滚动期间订购 postgreSQL 查询 (2)
- sql - 在 HIVE 上联合两个选择
- r - 将日期转换为年份和周数并返回
- c# - TelerikDropDownList 内部的空引用异常
- python - Django:模型关系问题
- c++ - 为什么在执行 SIMD 指令时需要 SSE 对齐?
- ruby-on-rails - Rails 6 显示 Active Record 集合代理对象