Skip to content

Commit

Permalink
fix(DBPreview): infinite loading on page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocorallo committed Feb 27, 2024
1 parent b62d230 commit d8c637f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/pages/DBPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useMemo, useState } from 'react'
import { DATABASE_REF, sectionInfo } from '../../utils/constants'
import {
Section,
Expand All @@ -22,7 +22,8 @@ interface DBPreviewProps {
}

export default function DBPreview({ dbs }: DBPreviewProps) {
const [db, setDb] = useState(dbs?.stable)
const [dbRef, setDbRef] = useState<DATABASE_REF>(DATABASE_REF.STABLE)
const db = useMemo(() => dbs?.[dbRef], [dbRef, dbs])

if (!db || !dbs) return <div style={baseStyle}>Loading...</div>
return (
Expand All @@ -34,7 +35,7 @@ export default function DBPreview({ dbs }: DBPreviewProps) {
{ value: DATABASE_REF.MAIN, label: 'Development' }
]}
defaultValue={DATABASE_REF.STABLE}
onChange={(v) => setDb(dbs[v as DATABASE_REF])}
onChange={(v) => setDbRef(v as DATABASE_REF)}
/>
{(
Object.entries(db).filter(([key]) => key != 'meta') as [
Expand Down

0 comments on commit d8c637f

Please sign in to comment.