Set value of a state using context api in hooks.client.ts #15155
Unanswered
IslamZaoui
asked this question in
Q&A
Replies: 2 comments
-
I think making a component is the best way for it <script lang="ts">
import { setPocketbase } from '@/context/pocketbase'
import { createInstance } from '@/pocketbase'
let { children } = $props()
$effect.pre(() => {
const pb = createInstance()
pb.authStore.loadFromCookie(document.cookie)
pb.authStore.onChange(() => {
document.cookie = pb.authStore.exportToCookie({ httpOnly: false })
}, true)
setPocketbase(pb)
})
</script>
{@render children()} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Code like this belongs in the root layout (or in a file called from said layout). |
Beta Was this translation helpful? Give feedback.
0 replies
No Sign up for free
to join this conversation on GitHub.
Already have an account?
No Sign in to comment
-
Hello, I want to set a global instance of pocketbase for user in
hooks.client.ts
this way the instance will always be up-to-date for the user across the app but I got this error
is there any work around or alternative way to do this?
Beta Was this translation helpful? Give feedback.
All reactions