diff --git a/src/state/shell/landing.tsx b/src/state/shell/landing.tsx index f071c79e39..b3034c94bd 100644 --- a/src/state/shell/landing.tsx +++ b/src/state/shell/landing.tsx @@ -1,4 +1,10 @@ -import {createContext, useContext, useState} from 'react' +import { + createContext, + type Dispatch, + type SetStateAction, + useContext, + useState, +} from 'react' import {logger} from '#/logger' @@ -16,11 +22,11 @@ type GroupChatJoinRequestLanding = { type LandingType = StarterPackLanding | GroupChatJoinRequestLanding | undefined -type SetContext = (v: LandingType) => void +type SetContext = Dispatch> const stateContext = createContext(undefined) stateContext.displayName = 'ActiveLandingStateContext' -const setContext = createContext((_: LandingType) => {}) +const setContext = createContext(() => {}) setContext.displayName = 'ActiveLandingSetContext' export function Provider({children}: {children: React.ReactNode}) { @@ -45,17 +51,18 @@ export const useActiveStarterPack = () => { export const useSetActiveStarterPack = () => { const setLanding = useSetActiveLanding() - const currentLanding = useActiveLanding() return (pack: {uri: string; isClip?: boolean} | undefined) => { if (!pack) { setLanding(undefined) } else { - if (currentLanding && currentLanding.type !== 'starterpack') { - logger.debug( - `[landing] Replacing ${currentLanding.type} landing with starterpack`, - ) - } - setLanding({type: 'starterpack', ...pack}) + setLanding(currentLanding => { + if (currentLanding && currentLanding.type !== 'starterpack') { + logger.debug( + `[landing] Replacing ${currentLanding.type} landing with starterpack`, + ) + } + return {type: 'starterpack', ...pack} + }) } } }