I am getting a TypeScript error on onToggle(eventKey === activeEventKey ? null : eventKey)
– This expression is not callable. Type ‘never’ has no call signatures. I am not sure how to resolve this.
import React from 'react'
import useAccordionContext from '../../../hooks/useAccordionContext'
interface Props {
eventKey: string | undefined
id: string | undefined
className: string
onClick: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void
}
const useAccordionClick = (
eventKey: string | undefined,
onClick: {
(event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void
(arg0: React.MouseEvent<HTMLButtonElement, MouseEvent>): void
}
) => {
const { onToggle, activeEventKey } = useAccordionContext()
return (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
onToggle(eventKey === activeEventKey ? null : eventKey)
if (onClick) {
onClick(event)
}
}
}
const Toggle: React.FC<Props> = ({
eventKey,
onClick,
children,
...otherProps
}) => {
const accordionClick = useAccordionClick(eventKey, onClick)
return (
<button
onClick={accordionClick}
{...otherProps}
>
{children}
</button>
)
}
export default Toggle