Skip to content

Commit

Permalink
fix TS errors in useInterval and usePrevious hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Dec 13, 2024
1 parent 7b198a4 commit 3e80018
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion frontend-v2/src/hooks/useInterval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ type IntervalProps = {
isDirty?: boolean;
};

const defaultCallback = () => null;

export default function useInterval({
callback,
delay,
isDirty = false,
}: IntervalProps) {
const savedCallback = useRef<() => void>();
const savedCallback = useRef<() => void>(defaultCallback);

useEffect(() => {
savedCallback.current = callback;
Expand Down
2 changes: 1 addition & 1 deletion frontend-v2/src/hooks/usePrevious.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from "react";

function usePrevious(value: any) {
const ref = useRef();
const ref = useRef(null);
useEffect(() => {
ref.current = value; //assign the value of ref to the argument
}, [value]); //this code will run when the value of 'value' changes
Expand Down

0 comments on commit 3e80018

Please sign in to comment.