зеркало из https://github.com/github/docs.git
Fix lang dropdown (#29444)
* Let be the caller, so events doesnt 403 on the first call * Declare function * Call all s so that the lang banner shows up consistently * Update get-session.ts
This commit is contained in:
Родитель
c3f1b91040
Коммит
ccb9cd28e3
|
@ -47,12 +47,16 @@ export async function fetchSession(): Promise<Session | null> {
|
|||
}
|
||||
|
||||
// React hook version
|
||||
const setFns = new Set<Function>()
|
||||
export function useSession() {
|
||||
const [session, setSession] = useState<Session | null>(sessionCache)
|
||||
setFns.add(setSession)
|
||||
const { asPath } = useRouter()
|
||||
// Only call `fetchSession` on the client
|
||||
useEffect(() => {
|
||||
fetchSession().then((session) => setSession(session))
|
||||
fetchSession().then((session) => {
|
||||
setFns.forEach((setSession) => setSession(session))
|
||||
})
|
||||
}, [asPath])
|
||||
return session
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче