@roochnetwork/rooch-sdk-kit
Version:
Rooch SDK Kit
33 lines (29 loc) • 930 B
JavaScript
// src/hooks/useSessionsStore.ts
import { useContext } from "react";
import { useStore } from "zustand";
// src/provider/roochProvider.tsx
import { createContext, useRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var RoochContext = createContext(null);
// src/hooks/useSessionsStore.ts
function useSessionStore(selector) {
const store = useContext(RoochContext);
if (!store) {
throw new Error(
"Could not find RoochSessionContext. Ensure that you have set up the RoochClientProvider."
);
}
return useStore(store, selector);
}
// src/hooks/useSession.ts
function useSession(scope) {
return useSessionStore(
(state) => state.sessions.find(
(item) => scope.includes("::") ? item.getScopes().find((_scope) => _scope === scope) : item.getScopes().find((_scope) => _scope.startsWith(scope)) !== void 0
)
);
}
export {
useSession
};
//# sourceMappingURL=useSession.js.map