首页 > 解决方案 > 如何将数据传递给孩子?反应

问题描述

这是我用来通过验证验证的简单代码:

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>;
}

我怎样才能添加它是哪个用户的信息?他有什么角色?

标签: reactjsreact-props

解决方案


推荐阅读