The LiveProvider
is employed to store the live state and subsequently distribute this state to other components within the application.
Starting with v4, LiveProvider
is optional and useSports
, useGames
and useSportsNavigation
don't use it any more. You can create your own source of truth, such as the URL /live in your application.
Usage
Wrap your application in LiveProvider
.
import { LiveProvider, ChainProvider } from '@azuro-org/sdk'
import { WagmiProvider } from 'wagmi'
import { QueryClientProvider } from '@tanstack/react-query'
import { polygonAmoy } from 'viem/chains'
const wagmiConfig = createConfig(config)
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
<WagmiProvider config={...}>
<QueryClientProvider client={...}>
<ChainProvider initialChainId={polygonAmoy.id}>
<LiveProvider initialLiveState={false}>
{children}
</LiveProvider>
</ChainProvider>
</QueryClientProvider>
</WagmiProvider>
)
}
The LiveProvider
requires access to the ChainProvider context.
Get stored context data.
import { useLive } from '@azuro-org/sdk'
const { isLive, changeLive } = useLive()
The isLive
state can only be true
in supported chains. If you change the appChain
to a different chain, isLive
will automatically become false
. Also, if you set the state of isLive
to true
, it will automatically switch the appChain to applicable network.
Supported chains:
Gnosis Mainnet
Polygon Mainnet
Polygon Amoy Testnet
The LiveProvider
stores the current state in a cookie under the key live
to restore isLive
state, for example, after a page refresh.
// Next.js example for app/layout.tsx
import { ChainProvider, LiveProvider } from '@azuro-org/sdk'
import { cookies } from 'next/headers'
export default function RootLayout(props: { children: React.ReactNode }) {
const { children } = props
const cookieStore = cookies()
const initialChainId = cookieStore.get('appChainId')?.value
const initialLiveState = JSON.parse(cookieStore.get('live')?.value || '')
return (
<html lang="en">
<body>
<WagmiProvider config={...}>
<QueryClientProvider client={...}>
<ChainProvider initialChainId={initialChainId}>
<LiveProvider initialLiveState={initialLiveState}>
<main>
{children}
</main>
</LiveProvider>
</ChainProvider>
</QueryClientProvider>
</WagmiProvider>
</body>
</html>
)
}
Props
{
children: React.ReactNode
initialLiveState?: boolean // your initial state
}
Return Value
{
isLive: boolean
changeLive: (value: boolean) => void
}