chore: fix type annotations (#6600)

This commit is contained in:
非法操作
2024-07-25 11:21:51 +08:00
committed by GitHub
parent 9815aab7a3
commit 585444c50c
12 changed files with 27 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
import { pinyin } from 'pinyin-pro'
import type { FC, RefObject } from 'react'
export const groupItems = (items, getFirstChar) => {
export const groupItems = (items: Array<any>, getFirstChar: (item: string) => string) => {
const groups = items.reduce((acc, item) => {
const firstChar = getFirstChar(item)
if (!firstChar || firstChar.length === 0)
@@ -34,9 +35,14 @@ export const groupItems = (items, getFirstChar) => {
return { letters, groups }
}
const IndexBar = ({ letters, itemRefs }) => {
const handleIndexClick = (letter) => {
const element = itemRefs.current[letter]
type IndexBarProps = {
letters: string[]
itemRefs: RefObject<{ [key: string]: HTMLElement | null }>
}
const IndexBar: FC<IndexBarProps> = ({ letters, itemRefs }) => {
const handleIndexClick = (letter: string) => {
const element = itemRefs.current?.[letter]
if (element)
element.scrollIntoView({ behavior: 'smooth' })
}