Skip to content

Commit

Permalink
feat(useSupported): support tracking reactivity for the callback func…
Browse files Browse the repository at this point in the history
…tion (#2904)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
ferferga and antfu committed Mar 28, 2023
1 parent 74b00a0 commit 55a32d9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/core/useSupported/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { tryOnMounted } from '@vueuse/shared'
import type { Ref } from 'vue-demi'
import { ref } from 'vue-demi'

export function useSupported(callback: () => unknown, sync = false) {
const isSupported = ref() as Ref<boolean>

const update = () => isSupported.value = Boolean(callback())

update()

tryOnMounted(update, sync)
return isSupported
import { computed } from 'vue-demi'
import { useMounted } from '../useMounted'

export function useSupported(callback: () => unknown) {
const isMounted = useMounted()

return computed(() => {
// to trigger the ref
// eslint-disable-next-line no-unused-expressions
isMounted.value
return Boolean(callback())
})
}

0 comments on commit 55a32d9

Please sign in to comment.