import type { DependencyList } from "react"; import { useEffect, useState } from "react"; /** * Like useState, except it will update the value when the default value changes */ export function useStateWithDeps(defaultValue: T | (() => T), deps: DependencyList) { const [value, setValue] = useState(defaultValue); // oxlint-disable-next-line react-hooks/exhaustive-deps useEffect(() => { setValue(defaultValue); }, [...deps]); return [value, setValue] as const; }