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

@dataql/nextjs

v0.1.2

Published

DataQL Next.js SDK with SSR/SSG support and offline-first capabilities

Readme

@dataql/nextjs

DataQL Next.js SDK with SSR/SSG support and offline-first capabilities.

Features

  • 🚀 Next.js Optimized: Built specifically for Next.js with SSR/SSG support
  • 🔄 Offline-First: Works seamlessly offline with automatic sync
  • Server-Side Rendering: Fetch data on the server for better SEO
  • 📊 Static Generation: Pre-generate pages with static data
  • 🎯 TypeScript: Full TypeScript support with type inference
  • 🔧 Easy Setup: Minimal configuration required

Installation

npm install @dataql/nextjs
# or
yarn add @dataql/nextjs

Quick Start

1. Setup DataQL Provider

Wrap your app with the DataQL provider:

// pages/_app.tsx
import { DataQLProvider } from "@dataql/nextjs";

export default function App({ Component, pageProps }) {
  return (
    <DataQLProvider
      config={{
        appToken: "your-app-token",
        databaseName: "my-app-db",
      }}>
      <Component {...pageProps} />
    </DataQLProvider>
  );
}

2. Use DataQL Hooks

// pages/users.tsx
import { useQuery, useMutation } from "@dataql/nextjs";

export default function UsersPage() {
  const { data: users, loading } = useQuery("users");
  const { create } = useMutation();

  const handleCreateUser = async () => {
    await create("users", { name: "John Doe", email: "[email protected]" });
  };

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <h1>Users</h1>
      <button onClick={handleCreateUser}>Add User</button>
      {users.map((user) => (
        <div key={user.id}>{user.name}</div>
      ))}
    </div>
  );
}

3. Server-Side Rendering

// pages/posts.tsx
import { GetServerSideProps } from "next";
import { ServerDataQLClient, useServerData } from "@dataql/nextjs";

export default function PostsPage({ initialPosts }) {
  const { data: posts } = useServerData("posts", {}, initialPosts);

  return (
    <div>
      <h1>Posts</h1>
      {posts.map((post) => (
        <article key={post.id}>
          <h2>{post.title}</h2>
          <p>{post.content}</p>
        </article>
      ))}
    </div>
  );
}

export const getServerSideProps: GetServerSideProps = async (context) => {
  const client = new ServerDataQLClient({
    appToken: process.env.DATAQL_APP_TOKEN,
    serverSide: true,
  });

  const initialPosts = await client.fetchForSSR("posts");

  return {
    props: {
      initialPosts,
    },
  };
};

4. Static Site Generation

// pages/products.tsx
import { GetStaticProps } from "next";
import { ServerDataQLClient, useStaticData } from "@dataql/nextjs";

export default function ProductsPage({ staticProducts }) {
  const { data: products } = useStaticData("products", {}, staticProducts);

  return (
    <div>
      <h1>Products</h1>
      {products.map((product) => (
        <div key={product.id}>
          <h2>{product.name}</h2>
          <p>${product.price}</p>
        </div>
      ))}
    </div>
  );
}

export const getStaticProps: GetStaticProps = async () => {
  const client = new ServerDataQLClient({
    appToken: process.env.DATAQL_APP_TOKEN,
    staticGeneration: true,
  });

  const staticProducts = await client.fetchForSSG("products");

  return {
    props: {
      staticProducts,
    },
    revalidate: 60, // Regenerate page every 60 seconds
  };
};

API Reference

Hooks

  • useQuery<T>(tableName, filter?) - Query data with offline support
  • useLiveQuery<T>(tableName, filter?) - Real-time queries with live updates
  • useMutation<T>() - Create, update, delete operations
  • useSync() - Sync status and manual sync control
  • useServerData<T>(tableName, filter?, initialData?) - SSR data with hydration
  • useStaticData<T>(tableName, filter?, staticData?) - SSG data support

Components

  • <DataQLProvider> - Context provider for DataQL
  • <DataQLWrapper> - Wrapper with SSR/SSG optimizations

Clients

  • DataQLNextClient - Main client for Next.js applications
  • ServerDataQLClient - Server-side client for SSR/SSG

Utilities

  • createNextDataQLConfig() - Create optimized configuration
  • getServerSideProps() - Helper for SSR data fetching
  • getStaticProps() - Helper for SSG data fetching
  • withDataQL() - Higher-order component wrapper

Configuration

const config = {
  appToken: "your-app-token",
  databaseName: "my-app-db",
  enablePersistence: true,
  serverSide: false,
  staticGeneration: false,
  syncConfig: {
    autoSync: true,
    syncInterval: 30000,
  },
  debug: false,
};

License

MIT