Skip to content

cookieToInitialState

Helper to convert a cookie string into initial state.

Import

ts
import { cookieToInitialState } from 'wagmi'

Usage

ts
import { cookieToInitialState } from 'wagmi'
import config from './config'

function handler(req: Request) {
  const initialState = cookieToInitialState(config, req.headers.cookie)
  // ...
}
ts
import { 
  createConfig, 
  http, 
  cookieStorage,
  createStorage
} from 'wagmi'
import { mainnet, sepolia } from 'wagmi/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  ssr: true,
  storage: createStorage({ 
    storage: cookieStorage,
  }), 
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

config

Config

Wagmi Config

string | null | undefined

The cookie string.

Return Type

State

Initial state.

Released under the MIT License.