🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

vue-memoized-composable

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-memoized-composable

A Vue composable that memoizes the result of a function

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

vue-memoized-composable

npm version npm downloads bundle JSDocs License

A Vue composable that memoizes the result of a function.

Install

pnpm install vue-memoized-composable

Example

import { createMemoizedComposable } from 'vue-memoized-composable'

const useUser = createMemoizedComposable((userId: Ref<string>) => {
  const { data } = useQuery({
    queryKey: ['user', userId],
    queryFn: () => fetchUser(userId.value),
  })

  console.log('useUser', userId.value)

  return data
})

const userId = ref('1')

const user1 = useUser(userId)
const user2 = useUser(userId)
// user1 and user2 will be the same
// useUser will be called only once
// logs: useUser 1

const userId3 = ref('2')
const user3 = useUser(userId3)
// user3 will be a new instance
// useUser will be called again
// logs: useUser 2

Thanks

License

MIT License © Croatia Lu

FAQs

Package last updated on 19 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts