Skip to content

Commit

Permalink
Fix eslint hook dependencies error with useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtitherington committed Oct 29, 2023
1 parent ddbe0dd commit 662316f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions frontend/src/components/toasts/Toast/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import toast from 'react-hot-toast';
import { MdInfoOutline } from 'react-icons/md';

Expand All @@ -12,17 +12,18 @@ interface ToastProps {
const Toast = ({ id, message, type = 'info', duration = 4000 }: ToastProps) => {
const [progress, setProgress] = useState(100);
const intervalRef = useRef<number | null>(null);
const color = type == 'info' ? 'bg-radial-ultra-light' : type == 'success' ? 'bg-green-600' : 'bg-red-600';
const color =
type == 'info' ? 'bg-radial-ultra-light' : type == 'success' ? 'bg-green-600' : 'bg-red-600';
const progressColor =
type == 'info' ? 'bg-gray-200' : type == 'success' ? 'bg-green-200' : 'bg-red-200';

const startProgress = () => {
const startProgress = useCallback(() => {
if (!intervalRef.current) {
intervalRef.current = window.setInterval(() => {
setProgress(prev => Math.max(prev - 100 / (duration / 10), 0));
}, 10);
}
};
}, [duration]);

const stopProgress = () => {
if (intervalRef.current) {
Expand All @@ -34,7 +35,7 @@ const Toast = ({ id, message, type = 'info', duration = 4000 }: ToastProps) => {
useEffect(() => {
startProgress();
return stopProgress;
}, []);
}, [startProgress]);

return (
<div
Expand Down

0 comments on commit 662316f

Please sign in to comment.