npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nuxt-use-prismic-api

v1.1.8

Published

A handy composable to query data from any Prismic API on your Nuxt application.

Readme

Nuxt usePrismicAPI

A handy composable to query data from any Prismic API on your Nuxt application. This composable allows you to query data from any Prismic API and abstracts the process a bit further to make it easy to retreive and display data on your Nuxt application. It works for both SSR and Static Nuxt applications up to v2.15.7 that are using @nuxtjs/composition-api and @nuxtjs/prismic modules.


Installation

Make sure you have @nuxtjs/composition-api and @nuxtjs/prismic modules installed. After that, install this package via npm or Yarn with the following commands.

npm:

npm i nuxt-use-prismic-api

Yarn:

yarn add nuxt-use-prismic-api

Import

Import it at any page or component you want to use like this:

import { usePrismicAPI } from 'nuxt-use-prismic-api'

Usage: Fetching Data

I tried to make the syntax for queries as simple as possible and also as similar as possible to the original Prismic API references. I'll go over and show examples of for each method below. I highly recommend taking a look at the official Prismic Documentation for references mentioned below.

Query

The composable exports a function called usePrismicAPI() and it takes a payload object as a parameter.

The payload object may look like this for a given query:

{
  data: string,
  method: string,
  query: {
    predicates: string,
    path: string,
    queryValue: string | string[],
    options: {
      page: number,
      pageSize: number
    }
  }
}

The data property is the dynamic variable that is exported by the usePrismicAPI() function. Basically, the exported constant can be named by the user. Queries return an array of objects and the value of the data property is used as a prefix for Pagination, Loading and Error objects as well as RefetchData function. Let's take look at an example query below.

const {
  blogPosts,
  blogPostsPagination,
  blogPostsRefetchData,
  blogPostsLoading,
  blogPostsError,
} = usePrismicAPI({
  data: 'blogPosts',
  method: 'query',
  query: {
    predicates: 'at',
    path: 'document.type',
    queryValue: 'blog_post',
    options: {
      page: 1,
      pageSize: 50
    },
  },
})

In the example above, the data property is named blogPosts which is going to be exported as a constant which can then be used within a template. Since this is a query that returns an array of objects, there is a dynamically named pagination object as blogPostsPagination which includes all the pagination data from the API. If there is no need to build a complex pagination and but a simple next and previous page navigation, then blogPostsRefetchData() function can be called and next_page and prev_page values from the blogPostsPagination can be given as a parameter. The function then does a refetch of the given page and returns the new data from the API. The query object must be present if your selected method is query. The query object takes in the key - value pairs as in the example above. For predicates, path and queryValue you can refer to the official Prismic Documentation. They are explained very well in there but in order to make it clear here is a rundown of what's actually happening in the example above.

The query is sent with a predicates value of 'at' which looks at a specific path which in this case is a document.type and the queryValue is set as blog_post that means this query is looking for documents with the type blog_post. The queryValue for some of these predicates can be different. For example any, takes in an array of strings instead of just a string in the case of at.

Currently only at, any, not and in predicates are supported but I'm working on adding other predicates as well.

getByUID

This is a very handy method that uses the getByUID helper function which returns a single object of a specified document type with a given UID. It's great for creating a single blog post page. Here is an example getByUID method with this composable.

const { singleBlogPost, singleBlogPostLoading, singleBlogPostError } = usePrismicAPI({
  data: 'singleBlogPost',
  method: 'getByUID',
  docType: 'blog_post',
  uid: 'my-first-blog-post'
})

In this example, there is no query object since our method is getByUID. Here, we just need to specify docType and the uid values. These can also be given dynamically. In fact, for a single blog post page, the uid value would most likely come in form of a param from the parent page.

getByID

This method is quite simple, as it only requires a document ID as a parameter.

const { item, itemLoading, itemError } = usePrismicAPI({
  data: 'item',
  method: 'getByID',
  id: '1b9d6bcdb8dfbbd4bed'
})

In this example, there is also no query object since our method is getByID. Here, we just need to specify the id value and this will return the document with the given id.

Currently only getByUID and getByID are supported but I'm working on adding getByIDs and other useful helper functions as well.


Usage: Rendering Data

You can either create your own custom components or you can use some of the powerful components that come with @nuxtjs/prismic module. Especially, for rich text fields I recommend using the prismic-rich-text component like in the example below. For more information, please refer to the official documentation of @nuxtjs/prismic module.

<prismic-rich-text :field="document.text" />