-
Currently with react query if you set // This is run on the server at run time when the user initially requests the page.
export default function Page(){
const caller = appRouter.createCaller()
// Lets say that when we search, we are ordering by the search string, then by creation date. The following
// would yeild the most recent 20 todos.
const initialData = caller.getTodos({search: ''})
return <ClientPage initialData={initialData} />
} // This is server side rendered. The code will run on the server once, then on the client from then-on.
export default function ClientPage({initialData: /*Our initialData type*/}){
const [search, setSearch] = useState('')
const todos = trpc.getTodos.useQuery(
{ search },
{
initialData: initialData,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false
staleTime: 5000,
},
);
return <>{/*Our rendered list of TODO's, with a search bar to search for new TODOs*/}</>
} The above example will let us render our todo list on page load with no popin since our data is gathered from the server component, then populated into client component during server-side rendering. The problem is when we now want to search for a new TODO; The above code will flicker our The desired outcome is to be able to populate |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Then implement it like that: export default function ClientPage({initialData: /*Our initialData type*/}){
const [search, setSearch] = useState('')
const todos = trpc.getTodos.useQuery(
{ search },
{
- initialData: initialData,
+ initialData: search === '' ? initialData : undefined,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false
staleTime: 5000,
},
);
return <>{/*Our rendered list of TODO's, with a search bar to search for new TODOs*/}</>
} What you have to understand is that |
Beta Was this translation helpful? Give feedback.
Then implement it like that:
What you have to understand is that
initialData
is use…