Skip to content

Setting initialData query key #5993

Answered by TkDodo
0ximjosh asked this question in General
Discussion options

You must be logged in to vote

AND the cache is empty except for our initial query key.

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 initialData is use…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@0ximjosh
Comment options

Answer selected by 0ximjosh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants