SSR support like Apollo Client's getDataFromTree? #594
-
Hello, With Apollo Client, you could just use And here is the source code for With this library, you have to write your fetch twice, once in Is there a way to avoid writing the queries twice and use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What I usually do is to keep SWR only for client-only data, if I need something with SSR and SWR I create a export function getTodos() {
// fetch todos and return them
}
export function useTodos(options) {
return useSWR("todos", getTodos, options)
} Then you can use |
Beta Was this translation helpful? Give feedback.
-
I haven't tested this but this could be really useful for this library https://github.com/ctrlplusb/react-tree-walker |
Beta Was this translation helpful? Give feedback.
What I usually do is to keep SWR only for client-only data, if I need something with SSR and SWR I create a
useMyData
Hook calling SWR and I export it together with the fetcher.Then you can use
useTodos
inside your components and callgetTodos
insidegetStaticProps
orgetServerSideProps
, and pass them to useTodos as initial data.