"use client"; import { getIdentityData } from "actions/getIdentityData"; import { createContext, useContext } from "react"; import useSWR, { KeyedMutator, mutate } from "swr"; import { DashboardState } from "./PageLayouts/DashboardLayout"; export type InterfaceState = { dashboards: { [id: string]: DashboardState | undefined }; }; type Identity = Awaited>; let IdentityContext = createContext({ identity: null as Identity, mutate: (() => {}) as KeyedMutator, }); export const useIdentityData = () => useContext(IdentityContext); export function IdentityContextProvider(props: { children: React.ReactNode; initialValue: Identity; }) { let { data: identity, mutate } = useSWR("identity", () => getIdentityData(), { fallbackData: props.initialValue, }); return ( {props.children} ); }