ant-design-vue/components/_util/hooks/useState.ts
tangjinzhou 75cf264040
refactor: tabs & card (#4732)
* refactor: tabs

* refactor: tabs

* fix: tabs hotreload error

* refactor: rename useRef

* feat: add leftExtra rightExtra

* refactor: tabs

* test: update tabs test

* refactor: card

* doc: update tabs demo

* refactor: add card style

* style: update vue dep
2021-10-07 09:23:36 +08:00

18 lines
475 B
TypeScript

import type { Ref } from 'vue';
import { ref } from 'vue';
export default function useState<T, R = Ref<T>>(
defaultStateValue?: T | (() => T),
): [R, (val: T) => void] {
const initValue: T =
typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue;
const innerValue = ref(initValue) as Ref<T>;
function triggerChange(newValue: T) {
innerValue.value = newValue;
}
return [innerValue as unknown as R, triggerChange];
}