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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devcaster/next

v0.0.6

Published

Tools for easy Farcaster development in Next.js

Downloads

8

Readme

@devcaster/next

License: MIT npm version

Devcaster allows anyone to declaratively create frames inside their existing Next.js sites, with just a few lines of code.

This library is intended for Next.js only (v14). We're working on future releases that can be used in other frameworks.

Getting Started

Install using your package manager of choice:

npm i @devcaster/next
yarn add @devcaster/next
pnpm i @devcaster/next
bun install @devcaster/next

Specify your base hub URL (with port) in your .env as HUB_URL

Create a middleware.ts file at the same level as your app directory. More on Next.js middleware

Inside your middleware.ts, add the frames middleware function:

import type { NextRequest } from "next/server";
import { framesMiddleware } from "@devcaster/next/frames";

export async function middleware(request: NextRequest) {
    return await framesMiddleware(request);
}

Finally, create a single frames folder inside your app directory, and add a route.ts file to it. Add the post handler to the route:

import { NextRequest } from "next/server";
import { framesPOST } from "@devcaster/next/frames";

export async function POST(request: NextRequest) {
    return await framesPOST(request);
}

Creating a Frame

To add a frame to a page, create a new FrameConfig in any page.ts file. Pass the config your initial state and the page's unaltered searchParams object:

export default function Home({
    searchParams,
}: {
    searchParams: Record<string, string>;
}) {
    const frame = new FrameConfig({ count: 0 }, searchParams);

Note: All frames must be created in server-side components.

In the above example, we have a simple frame state with a single count variable.

To create the frame elements, add a Frame component to your JSX, passing in your FrameConfig. Within your Frame, you can add buttons and images that will appear in the frame in a supported client:

<Frame frame={frame}>
	<FrameButton onClick={(f: typeof frame) => {
		f.state.count -= 1;
	}}>
		-
	</FrameButton>
	<FrameButton onClick={(f: typeof frame) => {
		f.state.count += 1;
	}}>
		+
	</FrameButton>
	<FrameImage src={`${process.env.BASE_URL}/image?count=${frame.state.count}`} />
</Frame>

You can pass your FrameButton components an onClick function to update the frames state, fetch the action sent by the Farcaster client, or even fetch external data.

You can use your frame's state to dynamically generate the returned image.

Note: For testing locally via tunneling, set a BASE_URL environment variable to your tunnel's url to override localhost.

To route to a new page after updating state, you can return a pathname from your onClick function:

<FrameButton onClick={(f: typeof frame) => {
	f.state.fid = f.action!.untrustedData.fid;
	return "/result";
}}>

On the /result page, you can continue to use the same state as long as the state object is consistent:

const frame = new FrameConfig<{ fid: number; }>({ fid: -1 }, searchParams);
if (frame.state.fid === -1) throw new Error("Failed to get FID");

const pokemon = await getPokemon(frame.state.fid);

You can also create a redirect button by providing an href prop rather than onClick. You can dynamically generate this link using both your frame state and the returned action data:

<FrameButton href={`${frame.origin}?index=${frame.state.index}&fid=${frame.action?.trustedData.message.data.fid}`}>
	Visit
</FrameButton>

Note: The redirect URL must have the same base domain as your site, per the Frame standard.

Text Input

Use the FrameInput component to accept user input:

<FrameInput placeholder="Type something!" />

Retrieve input from the frame.action in any of the button onClick callbacks.

See more examples

Contact @gregfromstl for any support.

More docs and examples coming soon...