Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
chen_gh committed Sep 6, 2024
1 parent ba5052b commit 64d094b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/static-past-time-picker/StaticPastTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function StaticPastTimePicker({

earliestApprove && options.push({ value: 'earliest', label: earliestInHistory });

const parseMode = (currentRange: string | undefined) => parseTimeMode(currentRange, options);
const parseMode = (current: string | undefined) => parseTimeMode(current, options);

Check failure on line 90 in src/static-past-time-picker/StaticPastTimePicker.tsx

View workflow job for this annotation

GitHub Actions / integration / Linting

The 'parseMode' function makes the dependencies of useEffect Hook (at line 131) change on every render. To fix this, wrap the definition of 'parseMode' in its own useCallback() Hook
const originMode = parseMode(timeRange) ?? 'quick';
const [mode, setMode] = React.useState<string | undefined>(originMode);

Expand Down Expand Up @@ -128,7 +128,7 @@ function StaticPastTimePicker({

React.useEffect(() => {
setMode(parseMode(timeRange) ?? 'quick');
}, [timeRange]);
}, [timeRange, parseMode]);

return (
<div data-testid="static-past-time-picker" className={prefixCls} {...rest}>
Expand Down

0 comments on commit 64d094b

Please sign in to comment.