useToggle
带有实用函数的布尔切换器。
用法
js
import { useToggle } from '@mpxjs/mpxuse-core'
const [value, toggle] = useToggle()
import { useToggle } from '@mpxjs/mpxuse-core'
const [value, toggle] = useToggle()
传递引用时,“useToggle”将返回一个简单的toggle函数:
js
import { useToggle } from '@mpxjs/mpxuse-core'
const isDark = ref(true)
const toggleDark = useToggle(isDark)
import { useToggle } from '@mpxjs/mpxuse-core'
const isDark = ref(true)
const toggleDark = useToggle(isDark)
类型声明
typescript
export interface UseToggleOptions<Truthy, Falsy> {
truthyValue?: MaybeComputedRef<Truthy>
falsyValue?: MaybeComputedRef<Falsy>
}
export declare function useToggle<Truthy, Falsy, T = Truthy | Falsy>(
initialValue: Ref<T>,
options?: UseToggleOptions<Truthy, Falsy>
): (value?: T) => T
export declare function useToggle<
Truthy = true,
Falsy = false,
T = Truthy | Falsy
>(
initialValue?: T,
options?: UseToggleOptions<Truthy, Falsy>
): [Ref<T>, (value?: T) => T]
export interface UseToggleOptions<Truthy, Falsy> {
truthyValue?: MaybeComputedRef<Truthy>
falsyValue?: MaybeComputedRef<Falsy>
}
export declare function useToggle<Truthy, Falsy, T = Truthy | Falsy>(
initialValue: Ref<T>,
options?: UseToggleOptions<Truthy, Falsy>
): (value?: T) => T
export declare function useToggle<
Truthy = true,
Falsy = false,
T = Truthy | Falsy
>(
initialValue?: T,
options?: UseToggleOptions<Truthy, Falsy>
): [Ref<T>, (value?: T) => T]