convex-helpers
Advanced tools
Comparing version 0.1.34-alpha.2 to 0.1.34-alpha.3
@@ -68,2 +68,3 @@ "use client"; | ||
refreshSessionId, | ||
ssrFriendly, | ||
}), [ssrFriendly, initial, sessionId, refreshSessionId]); | ||
@@ -74,3 +75,3 @@ return React.createElement(SessionContext.Provider, { value }, children); | ||
export function useSessionQuery(query, ...args) { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const skip = args[0] === "skip" || sessionId === undefined; | ||
@@ -83,3 +84,3 @@ const originalArgs = args[0] === "skip" ? {} : args[0] ?? {}; | ||
export function useSessionMutation(name) { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const originalMutation = useMutation(name); | ||
@@ -99,3 +100,3 @@ return useCallback((...args) => { | ||
export function useSessionAction(name) { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const originalAction = useAction(name); | ||
@@ -127,7 +128,10 @@ return useCallback((...args) => { | ||
} | ||
const sessionId = ctx.sessionId; | ||
if (ssrFriendly !== "ssr" && sessionId === undefined) { | ||
throw new Error("Session ID is not available yet."); | ||
if (ssrFriendly !== "ssr" && ctx.ssrFriendly) { | ||
throw new Error("When you use ssrFriendly with ConvexProvider, " + | ||
"you need to pass 'ssr' to useSessionId."); | ||
} | ||
return [sessionId, ctx.refreshSessionId]; | ||
if (!ctx.ssrFriendly && ctx.sessionId === undefined) { | ||
throw new Error("Session ID invalid. Clear your storage?"); | ||
} | ||
return [ctx.sessionId, ctx.refreshSessionId]; | ||
} | ||
@@ -134,0 +138,0 @@ export function useSessionStorage(key, initialValue) { |
{ | ||
"name": "convex-helpers", | ||
"version": "0.1.34-alpha.2", | ||
"version": "0.1.34-alpha.3", | ||
"description": "A collection of useful code to complement the official convex package.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -50,2 +50,3 @@ "use client"; | ||
refreshSessionId: RefreshSessionFn; | ||
ssrFriendly?: boolean; | ||
} | null>(null); | ||
@@ -126,2 +127,3 @@ | ||
refreshSessionId, | ||
ssrFriendly, | ||
}), | ||
@@ -139,3 +141,3 @@ [ssrFriendly, initial, sessionId, refreshSessionId] | ||
): FunctionReturnType<Query> | undefined { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const skip = args[0] === "skip" || sessionId === undefined; | ||
@@ -153,3 +155,3 @@ const originalArgs = args[0] === "skip" ? {} : args[0] ?? {}; | ||
>(name: Mutation) { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const originalMutation = useMutation(name); | ||
@@ -179,3 +181,3 @@ | ||
) { | ||
const [sessionId] = useSessionId(); | ||
const [sessionId] = useSessionId("ssr"); | ||
const originalAction = useAction(name); | ||
@@ -220,7 +222,12 @@ | ||
} | ||
const sessionId = ctx.sessionId; | ||
if (ssrFriendly !== "ssr" && sessionId === undefined) { | ||
throw new Error("Session ID is not available yet."); | ||
if (ssrFriendly !== "ssr" && ctx.ssrFriendly) { | ||
throw new Error( | ||
"When you use ssrFriendly with ConvexProvider, " + | ||
"you need to pass 'ssr' to useSessionId." | ||
); | ||
} | ||
return [sessionId!, ctx.refreshSessionId] as const; | ||
if (!ctx.ssrFriendly && ctx.sessionId === undefined) { | ||
throw new Error("Session ID invalid. Clear your storage?"); | ||
} | ||
return [ctx.sessionId!, ctx.refreshSessionId] as const; | ||
} | ||
@@ -227,0 +234,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
495775
9036