Feat/use searchparams as state (#2554)

Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
Rozstone 2024-02-26 12:52:59 +08:00 • committed by GitHub
commit d93288f711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 9 deletions

View file

@ -1,7 +1,7 @@
'use client'
// Libraries
import { useRef, useState } from 'react'
import { useRef } from 'react'
import { useTranslation } from 'react-i18next'
import useSWR from 'swr'
@ -15,6 +15,9 @@ import TabSlider from '@/app/components/base/tab-slider'
// Services
import { fetchDatasetApiBaseUrl } from '@/service/datasets'
// Hooks
import { useTabSearchParams } from '@/hooks/use-tab-searchparams'
const Container = () => {
const { t } = useTranslation()
@ -23,7 +26,9 @@ const Container = () => {
{ value: 'api', text: t('dataset.datasetsApi') },
]
const [activeTab, setActiveTab] = useState('dataset')
const [activeTab, setActiveTab] = useTabSearchParams({
defaultTab: 'dataset',
})
const containerRef = useRef<HTMLDivElement>(null)
const { data } = useSWR(activeTab === 'dataset' ? null : '/datasets/api-base-info', fetchDatasetApiBaseUrl)