initialData affecting "status" variable? #355
Replies: 3 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
In your example, you're right, it doesn't make much sense, because your initial data is hard coded. It makes more sense when you have something like |
Beta Was this translation helpful? Give feedback.
-
Hmm, I see what you're saying. I think I did a bad job articulating/exemplifying my issue. I'm using Next.js to server-render a page. When the page loads, it fetches a list of accounts in This table has a bunch of UI controls for filtering the data, (e.g., by timeframe) and because changing these filters involves asking my API for new data, I'm using What doesn't make sense to me is that I'm pre-populating the state UI controls according to how I asked my API for data in const [timeframe, setTimeframe] = React.useState('foo');
const { data } = useQuery(['accounts', timeframe], api.fetchAccounts, {initialData: initialAccounts}) However, Does that make sense? |
Beta Was this translation helpful? Give feedback.
-
Howdy again!
I'm noticing something weird when I use the
initialData
option withuseQuery
in an SSR context. When my component mounts,status
starts off as "success" which is what I expect. However, when one of my query key changes and my query function fires,status
remains as "success" which I don't expect. I would expect this variable to cycle through loading, success, and error as it would normally.https://codesandbox.io/s/relaxed-wilson-rp8dp?file=/src/App.js
I'm fairly new to the land of SSR – perhaps I'm misunderstanding the role of
initialData
in pre-populating a query with data from the server?Beta Was this translation helpful? Give feedback.
All reactions