mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-15 09:21:25 +08:00
75cf264040
* 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
18 lines
475 B
TypeScript
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];
|
|
}
|