Explorar o código

新增baseHook

wyling007 %!s(int64=3) %!d(string=hai) anos
pai
achega
6c9e6758a0
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      src/hooks/base/useState.ts

+ 10 - 0
src/hooks/base/useState.ts

@@ -0,0 +1,10 @@
+import { ref } from "vue";
+import type { Ref, UnwrapRef } from "vue";
+
+export type ReturnUseState<T> = [Ref<UnwrapRef<T>>, (newValue: UnwrapRef<T>) => UnwrapRef<T>];
+
+export default function useState<T>(value: T): ReturnUseState<T> {
+	const state = ref(value);
+	const setState = (newValue: UnwrapRef<T>) => (state.value = newValue);
+	return [state, setState];
+}