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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nuxt-query-sync

v1.0.6

Published

My new Nuxt module

Downloads

83

Readme

nuxt-query-sync

Overview

This module is a utility designed for Nuxt applications that seamlessly synchronizes Nuxt Ref or Reactive objects with URL query parameters. This ensures that the state of your application can be persisted and retrieved via the URL, enhancing the user experience by allowing state to be shared or restored through URLs.

Features

  • Automatic Synchronization: Keeps Ref or Reactive objects in sync with URL query parameters.
  • Initial Load Support: Initializes objects with values from query parameters if they exist on initial load.
  • Flexible Usage: Supports both Ref and Reactive objects with minimal configuration.

Installation

To use this module in your Nuxt application, follow these steps:

  1. Install the package (assuming it's published on npm, adjust the command if necessary):

    # Using npm
    $ npm add -D nuxt-query-sync
    
    # Using pnpm
    $ pnpm add -D nuxt-query-sync
    
    # Using yarn
    $ yarn add -D nuxt-query-sync
    
    # Using bun
    $ bun add -D nuxt-query-sync
  2. Add the module to your Nuxt configuration:

    // nuxt-config.ts
    export default defineNuxtConfig({
      modules: ['nuxt-query-sync'],
    })

Usage

With Ref

To persist a Ref in the URL query parameters, use the usePersistence function. You need to provide a key which will be used as the query parameter key.

import usePersistence from 'nuxt-query-sync';

const count = ref(0);
usePersistence(count, 'count');

In this example, the count Ref will be synchronized with the count query parameter. Any changes to count will update the URL.

With Reactive

To persist a Reactive object, simply pass it to usePersistence without a key. The keys of the Reactive object will be used as query parameter keys.

import usePersistence from 'nuxt-query-sync';

const state = reactive({ name: 'John', age: 30 });
usePersistence(state);

Here, the state object will be synchronized with corresponding query parameters (e.g., name and age).

API

usePersistence<T>(item: T, key?: string): T

  • Parameters:

    • item: The Nuxt Ref or Reactive object to be persisted. If a Ref, key must be provided.
    • key (optional): The query parameter key for Ref items. Not applicable for Reactive items.
  • Returns: The original Ref or Reactive object with persistence logic applied.

  • Throws: An error if an unsupported type is provided or if a Ref is used without a key.

Example

import usePersistence from 'nuxt-query-sync';

// Example with Ref
const count = ref(0);
usePersistence(count, 'count');

// Example with Reactive
const state = reactive({ name: 'John', age: 30 });
usePersistence(state);

License

This module is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.

Support

For questions or support, please open an issue on GitHub