From 709fb35b03a673ee84fb659f528cebd0a089b93b Mon Sep 17 00:00:00 2001
From: mackt <1033530438@qq.com>
Date: Mon, 29 Apr 2024 11:17:41 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=AF=8F=E6=AC=A1=E8=BF=9B=E5=85=A5?=
=?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/app/layout.tsx | 3 ++-
src/components/App.tsx | 21 +++++++++++++++++++++
src/components/Header/Auth.tsx | 2 --
src/components/index.ts | 1 +
src/store/user.ts | 5 +++++
5 files changed, 29 insertions(+), 3 deletions(-)
create mode 100644 src/components/App.tsx
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 2acdf8a..05c8b57 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -3,7 +3,7 @@ import Script from 'next/script';
import { Toaster } from '@/components/ui/toaster';
-import { Header, Footer, PlayerBar, ScrollTopButton } from '@/components';
+import { Header, App, Footer, PlayerBar, ScrollTopButton } from '@/components';
import './globals.css';
@@ -31,6 +31,7 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
return (
+
{children}
diff --git a/src/components/App.tsx b/src/components/App.tsx
new file mode 100644
index 0000000..730e59b
--- /dev/null
+++ b/src/components/App.tsx
@@ -0,0 +1,21 @@
+'use client';
+
+import { useEffect } from 'react';
+
+import { useShallow } from 'zustand/react/shallow';
+
+import { useUserStore } from '@/store';
+
+export default function APP() {
+ const { getUserInfo } = useUserStore(
+ useShallow((state) => ({
+ getUserInfo: state.getUserInfo,
+ })),
+ );
+
+ useEffect(() => {
+ getUserInfo();
+ }, []);
+
+ return ;
+}
diff --git a/src/components/Header/Auth.tsx b/src/components/Header/Auth.tsx
index ba23a45..c5e0cc8 100644
--- a/src/components/Header/Auth.tsx
+++ b/src/components/Header/Auth.tsx
@@ -13,8 +13,6 @@ export default function Auth() {
const { userInfo } = useUserStore(
useShallow((state) => ({
userInfo: state.userInfo,
- showLogin: state.showLogin,
- setShowLogin: state.setShowLogin,
})),
);
diff --git a/src/components/index.ts b/src/components/index.ts
index c08188e..6ac7051 100644
--- a/src/components/index.ts
+++ b/src/components/index.ts
@@ -1,3 +1,4 @@
+export { default as App } from './App';
export { default as Logo } from './Logo';
export { default as Header } from './Header/Header';
export { default as Footer } from './Footer/Footer';
diff --git a/src/store/user.ts b/src/store/user.ts
index ea5302c..5598eb3 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -1,3 +1,8 @@
+/**
+ * 这里需要改一下,最好能在初始化的时候刷新一次 UserInfo
+ * https://github.com/pmndrs/zustand/blob/main/docs/integrations/persisting-store-data.md#usage-in-nextjs
+ */
+
import { produce } from 'immer';
// import { setCookie } from 'nookies';
import { create } from 'zustand';