Skip to content

Commit

Permalink
do not call "useState" conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
0div committed Nov 26, 2024
1 parent 08bf46f commit b3d5457
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/web/src/components/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ function VersionedNavigationGroup({
isLast?: boolean
}) {
const router = useRouter()

// Manage the state of the current version of the API reference
const versions = Object.keys(group.versionedItems)
const [curVersion, setCurVersion] = useState(versions[0])

// If this is the mobile navigation then we always render the initial
// state, so that the state does not change during the close animation.
// The state will still update when we re-open (re-render) the navigation.
Expand All @@ -104,9 +109,6 @@ function VersionedNavigationGroup({
return null
}

const versions = Object.keys(group.versionedItems)
const [curVersion, setCurVersion] = useState(versions[0])

return (
<li className={clsx('relative', className)}>
<div className="pl-2 mb-1 flex items-center justify-between gap-1">
Expand Down

0 comments on commit b3d5457

Please sign in to comment.