mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-17 21:27:16 +02:00
Split codebase (#455)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
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<T>(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;
|
||||
}
|
||||
Reference in New Issue
Block a user