Saltar al contenido principal

Function: useAstroFindEntry()

useAstroFindEntry<T>(items, value, keyFrom?): T | null

Defined in: src/adapters/astro/astro.service.ts:111

Find a collection entry by slug or custom key.

Type Parameters

T

T

Parameters

items

T[]

Collection items to search

value

string

Value to match (slug, id, etc.)

keyFrom?

(item) => string | number

Optional function to extract the key from an item

Returns

T | null

Matched item or null

Example

const posts = await getCollection("blog");
const post = useAstroFindEntry(posts, "hello-world");
if (post) console.log(post.data.title);