You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thank you for the amazing work that is nanostoes and nanoquey. I have a question:
In the following example
import{useState,useEffect}from'preact/hooks'import{nanoquery}from'@nanostores/query';import{FunctionComponent}from'preact';const[createFetcherStore]=nanoquery({fetcher: ()=>Promise.reject('Please provide the fetcher property'),});const$user=createFetcherStore<{name: string}>('user',{fetcher: ()=>fetch('https://jsonplaceholder.typicode.com/users/1').then(res=>res.json()),dedupeTime: Infinity})constUser: FunctionComponent<{count: number}>=({count})=>{const[user,setUser]=useState($user.get().data)useEffect(()=>{return$user.subscribe((usr)=>{setUser(usr.data)})},[])useEffect(()=>{console.log(user);},[user])return!user ? 'loading...' : `${user.name}${count}`}exportfunctionApp(){const[count,setCount]=useState(0)useEffect(()=>{constintervalId=setInterval(()=>{setCount(prev=>prev+1)},200)return()=>clearInterval(intervalId);})return(<>{count%2===0 ? 'NO' : <Usercount={1}/>}</>)}
The console keeps logging undefined before logging the correct value, even though the fetcher is not rerunning the fetcher promise every time. I believe this is because the store resets its state to {loading: false} in this line.
From my perspective, since the data is already in the cache, the fetcherStore should return the data, not return an intermediate { loading: false} and then return the data that already exists in the cache.
My question is: Is this an intentional behaviour ? If so can you please explain the reason ?
Thank you.
The text was updated successfully, but these errors were encountered:
Hi, thank you for the amazing work that is nanostoes and nanoquey. I have a question:
In the following example
The console keeps logging
undefined
before logging the correct value, even though the fetcher is not rerunning the fetcher promise every time. I believe this is because the store resets its state to{loading: false}
in this line.From my perspective, since the data is already in the cache, the fetcherStore should return the data, not return an intermediate
{ loading: false}
and then return the data that already exists in the cache.My question is: Is this an intentional behaviour ? If so can you please explain the reason ?
Thank you.
The text was updated successfully, but these errors were encountered: