Skip to content

Commit bf4d7af

Browse files
committed
fix: resolve the BodyCell onClick handler auto call issue
1 parent d8b3412 commit bf4d7af

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/components/BodyCell.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from 'react';
1+
import React, { useMemo, useCallback } from 'react';
22
import BodyCellContent, { BodyCellContentProps } from './BodyCellContent';
33
import { BodyCellType } from '../types';
44
import styles from './styles.less';
@@ -16,8 +16,10 @@ export interface BodyCellProps {
1616
const BodyCell = ({ data, locale, contentComponent: ContentComponent, onClick, className, contentClassName }: BodyCellProps): JSX.Element => {
1717
const classes = useMemo(() => classnames(styles.body__cell, className), [className]);
1818

19+
const handleClick = useCallback(() => onClick && onClick(data), [data, onClick]);
20+
1921
return (
20-
<li className={classes} onClick={(!!onClick && onClick(data)) || undefined} role="presentation">
22+
<li className={classes} onClick={(!!onClick && handleClick) || undefined} role="presentation">
2123
<BodyCellContent data={data} locale={locale} component={ContentComponent} className={contentClassName} />
2224
</li>
2325
);

0 commit comments

Comments
 (0)