Skip to content

Commit

Permalink
fix(ui): resolve invalid hook call in search result page (#669)
Browse files Browse the repository at this point in the history
## What type of PR is this?

/kind bug

## What this PR does / why we need it:

This PR resolves an invalid hook call in the search result page by
moving the `useTranslation` hook inside function components, fixing a
runtime error caused by incorrect hook usage. It ensures that hooks are
only called within React function components.

## Which issue(s) this PR fixes:

Fixes #
  • Loading branch information
elliotxx authored Dec 17, 2024
1 parent bb5db2d commit b6b1428
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ui/src/pages/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { useAxios } from '@/utils/request'
import styles from './styles.module.less'

const { Search } = Input
const { t } = useTranslation()
const Option = AutoComplete.Option

export const CustomDropdown = props => {
Expand All @@ -47,9 +46,7 @@ export const CustomDropdown = props => {
>
<Option value={option.value}>
<span>{option.value}</span> -{' '}
<span style={{ color: '#999' }}>
{option.value || t('DefaultTag')}
</span>
<span style={{ color: '#999' }}>{option.value || <></>}</span>
</Option>
</div>
))}
Expand All @@ -58,7 +55,6 @@ export const CustomDropdown = props => {
}

const Result = () => {
const { t } = useTranslation()
const location = useLocation()
const navigate = useNavigate()
const [pageData, setPageData] = useState<any>()
Expand All @@ -76,6 +72,8 @@ const Result = () => {
getHistoryList('naturalHistory') || [],
)

const { t } = useTranslation()

function cacheNaturalHistory(key, val) {
const result = cacheHistory(key, val)
setNaturalOptions(result)
Expand Down

0 comments on commit b6b1428

Please sign in to comment.