Next.js - React Server Component

How to use Quirks utilities with React Server Components (RSC) in Next.js.

By using cookies, supporting RSCs becomes possible, and there are various utilities available to ease their integration with the App router.

Notice

This functionality requires a version of @quirks/store >= 0.25.0

All the following utilities requires you to pass a raw cookie string to them, so then they'll be able to parse it and return you to correct state result.

For example using nextjs you can retrieve by doing this:

import { cookies } from 'next/headers';
 
const getQuirksState = async () => {
  const results = await cookies();
  const quirks = results.get('quirks');
 
  return quirks?.value;
}

getConnect

Returns information about the current wallet and about the status of the connection.

import {  } from "@quirks/ssr";
 
 
const {
  ,
  ,
  ,
  ,
  ,
  ,
  ,
  ,
} = ();

getChain

If you use the name of a previously configured chain as parameter, it will return information about that chain. If the wallet is connected, it will also return the address for that wallet/chain pair.

Note

The list of supported chains depends on the wallet you are using; not all wallets allow you to add custom chains. Therefore, it may not be possible to get information for some chains.

import {  } from "@quirks/ssr";
 
 
/**
 * The name of the chain for which you want to obtain information
 * corresponds to the one you have used in the Config object.
 */
const  = "osmosis";
 
const { ,  } = (, );

getChains

Returns information about all connected chains. If the wallet is connected, it will also return the address for that wallet/chain pairs.

import {  } from "@quirks/ssr";
 
 
const { , , ,  } = ();

Example using NextJS

/app/server-component-example.tsx
import { ,  } from "@quirks/ssr";
import {  } from 'next/headers';
 
export const  = async () => {
  const  = await ();
  const  = .("quirks")?.;
 
  if (!) {
    return null
  }
 
  const {  } = ();
  const {  } = (, "osmosis");
 
  if (!) {
    return <>Disconnected</>;
  }
 
  return (
    <>
      Server Component
      <>Chain Name: Osmosis</>
      <>Address: {}</>
    </>
  );
};

On this page