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

reason-nextjs

v0.2.3

Published

Type definitions for Next.js.

Readme

Next.js, but in ReasonML and Bucklescript!

Type definitions for Next.js.

State:

  • Mostly complete type definitions. Feel free to open a pull-request to add more!
  • Wraps API for Next version 9.x.x on NPM
  • Only works with Bucklescript 7.x and above.

The Basics.

  1. Have a reason project already set up

  2. Install:

npm install --save next@9 reason-nextjs

(Notice how you installed both next and nextdotbs!)

  1. Add "reason-nextjs" to your "bs-dependencies" in your "bsconfig.json"

  2. Install ReasonReact

  3. mkdir pages

  4. Make a file: src/pages/WelcomePage.re that defines a React component named default.

open React;
open Next;

[@react.component]
let default = () => {
  <div>
    <Head>
      <title> "Welcome"->string </title>
    </Head>
    "Welcome to Next"->string
  </div>;
};
  1. Symlink that file into the pages directory:

cd pages && ln -s ../src/pages/WelcomePage.bs.js welcome.js

The symlinking allows us to still use the .bs.js postfix for Reason files, and also allows us to use dynamic routing and name files with square brackets inside of the pages directory without upsetting bsb.

  1. Launch Next and open the browser, etc. as explained in the Next.js docs

Data Fetching

Next performs data fetching for page components by looking for a static function on the component class called getInitialProps. This isn't a pattern that ReasonReact likes, so instead, these wrappings expose a function called assignPropsFetcher that you pass your default value (from creating the React component) to:

open React;
open Next;

[@react.component]
let default = (~message: string) => {
  <div>
    <Head>
      <title> "Welcome"->string </title>
    </Head>
    "Welcome to Next"->string
  </div>;
};

// Notice how I match the props for the component above!
type props = {message: option(Post.t)};

let fetcher: propsFetcher(props) =
  ({req, query}) => {
    // ... do some async stuff we don't show here and get a value called "message" in scope. 🧙‍♂️
    {message: message}->Js.Promise.resolve;
  };

default->assignPropsFetcher(fetcher);

That's most of it! So to re-cap, you can use it just like Next.js except:

  • Symlink your compiled Reason artifacts into the correct location in the pages folder.
  • Use assignPropsFetcher instead of getInitialProps.
  • The req param that gets passed into the props fetcher will be None on the client, but will be an object with a headers field on the server. If you're making a request from your own server to your own API to populate data, you can get the host and use it as the host for your HTTP request.

Other things to note:

  • A Head React component is available for inserting tags into the head of the document.
  • A Link React component is availalbe for slick in-app navigation.

Usage with Serbet.

You may want to run Next alongside your own API, and you may be using Serbet for that. Here's how they can work together:

open Async;

let nextServer =
  NextServer.make({
    dev:
      !
        Node.Process.process##env
        ->Js.Dict.get("NODE_ENV")
        ->Belt.Option.map(a => a == "production")
        ->Belt.Option.getWithDefault(false),
  });

{
  let%Async _ = nextServer->NextJSServer.prepare;
  let app =
    Serbet.application([
      // your API routes here
    ]);
  app.router->Express.Router.use(nextServer->NextServer.getRequestHandler);
  async();
};