help: how to use ssrRef with useFetch
See original GitHub issue**📚 What i am trying to do? ** i really need use a shared ref with useFetch how can i do that
🔍 What have i tried? i tried this :
import { Ref, ssrRef } from '@nuxtjs/composition-api'
const sharedMap = new Map()
function sharedRef<T>(value: T, key: string): Ref
function sharedRef<T>(value: T, _?): Ref
function sharedRef<T>(value: T, key: string): Ref {
const givenKey = key || value
if (sharedMap.has(givenKey)) {
return sharedMap.get(givenKey)
}
const newRef = ssrRef(key ? value : null, givenKey as string)
sharedMap.set(givenKey, newRef)
return newRef
}
export { sharedRef }
to avoid twice hydration, am i in right way? if not how can i do this?
ℹ️ Additional context i have another problem too, i want to check if my shared ref has data don’t fetch it with client navigation therefor :
const { fetch } = useFetch(() =>{
if(mySharedRef.value){return}
} ...)
it’s totally fine in develop env but when i deployed it, data has gone after a quick showing, but page source is okay.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
help: Some problem with useFetch #18 - GitHub
I was trying to build a composable method where it has the state wrapped within a ref and some methods to get and...
Read more >useFetch - Nuxt Composition API
You can access the Nuxt fetch() hook within the composition API. ... the state would be sent from server to client "twice", via...
Read more >Handling server-side applications with Nuxt's Composition API
In this post, we'll take a look at how the Nuxt Composition API works and best practices for using it in projects.
Read more >Vue to Nuxt: Server-Side Rendering Example
We can do rendering work on the server side a way faster so the user ... Switching refs to ssrRefs and useFetch to...
Read more >Nuxt Composition API, updating 'state', not reflected on UI ...
Looking for directions on how to get this to work, improve any of the code i've currently setup. javascript · nuxt.js · vuex...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ziaadini Great 👍
thanks. i had some issue with ssrRef and i fix it by this code with vuex
inside
store/index.ts
mutation:and every thing work as expected now and i can useFetch because i’m using vuex, not ssrRef. i think it’s okay now isn’t it?