Server Side Rendering (Next.js) - Using Cookies

Guide on setting up Server Side Rendering (SSR) with Next.js using cookies for session storage.

A good alternative to the usage of QuirksNextProvider is to use cookies to store session data, which can also be useful for the server. Additionally, this method allows for the use of React Server Components with quirks.

Notice

This functionality requires @quirks/store version 0.25.0 or higher

Note

I use this approach for the homepage of this site!

Installation

Install the package

npm install @quirks/ssr

Usage with App Router

Create a providers.tsx file:

/app/providers.tsx
"use client";
 
import {
   as ,
   as ,
} from 'chain-registry/mainnet/osmosis';
import {  } from "@quirks/react";
import { Config } from "@quirks/store";
import { ,  } from "@quirks/wallets";
import { ,  } from "@quirks/ssr";
import {  } from "react";
 
const  = ({
  : [, ],
  : [],
  : [],
});
 
export const  = ({ ,  }: <{ ?: string }>) => {
  const  = (
    ,
    ,
  );
 
  return < ={}>{}</>;
};

Import it inside your layout.tsx:

/app/layout.tsx
// @filename: layout.tsx
import {  } from "react";
import {  } from "next/headers";
import {  } from "./provider";
 
export default async function ({
  ,
}: {
  : React.;
}) {
  /* From NextJS 15 `cookies` are async */
  const  = await ();
  const  = .("quirks")?.;
 
  return (
    < ="en">
      <>
        < ={}>{}</>
      </>
    </>
  );
}

You did it 🎉! Now you can start using it as described inside quick start.

Usage with Pages Router

Add the providers inside your _app.tsx:

/pages/_app.tsx
import {
   as ,
   as ,
} from 'chain-registry/mainnet/osmosis';
import {  } from "@quirks/react";
import { Config } from "@quirks/store";
import { ,  } from "@quirks/wallets";
import { ,  } from "@quirks/ssr";
import {  } from "cookies-next";
import type {  } from "next/app";
import type { , ,  } from "next";
 
const  = ({
  : [, ],
  : [],
  : [],
});
 
export const  = (async ({ ,  }: ) => {
  const  = await ('quirks', { ,  });
  
  return {
    : { :  || null }
  }
}) satisfies <{ : string | null }>
 
function ({ , ,  }:  & <typeof >) {
  const  = (
    ,
    ,
  );
 
  return (
    < ={}>
      < {...} />
    </>
  );
}

You did it 🎉! Now you can start using it as described inside quick start.

On this page