import { Dispatch, SetStateAction, useState } from "react"; export function useProxyState(initial: T, setter: (value: T) => void): [T, Dispatch>] { const [value, proxy] = useState(initial); return [value, (newValue: SetStateAction) => { proxy(newValue); setter(typeof newValue === "function" ? (newValue as any)(value) : newValue); }]; }