react-query#dehydrate TypeScript Examples
The following examples show how to use
react-query#dehydrate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: securedProps.ts From frontend with MIT License | 6 votes |
securedAdminProps: (
namespaces?: string[],
resolveEndpoint?: (ctx: GetServerSidePropsContext) => string,
) => GetServerSideProps<Session> = (namespaces, resolveEndpoint) => async (ctx) => {
const result = securedPropsWithTranslation(namespaces)
const response = await result(ctx)
if ('props' in response) {
const client = new QueryClient()
if (resolveEndpoint) {
const { accessToken } = await response.props
await client.prefetchQuery(resolveEndpoint(ctx), authQueryFnFactory(accessToken))
}
return {
props: {
...response.props,
dehydratedState: dehydrate(client),
},
}
}
return response
}
Example #2
Source File: index.tsx From frontend with MIT License | 6 votes |
getServerSideProps: GetServerSideProps = async ({ query, locale }) => {
const { slug } = query
const client = new QueryClient()
await client.prefetchQuery(`/campaign/${slug}`, queryFn)
return {
props: {
slug,
...(await serverSideTranslations(locale ?? 'bg', [
'common',
'auth',
'validation',
'campaigns',
'irregularity',
])),
dehydratedState: dehydrate(client),
},
}
}
Example #3
Source File: irregularity.tsx From frontend with MIT License | 6 votes |
getServerSideProps: GetServerSideProps = async ({ query, locale }) => {
const { slug } = query
const client = new QueryClient()
await client.prefetchQuery(`/campaign/${slug}`, queryFn)
return {
props: {
slug,
...(await serverSideTranslations(locale ?? 'bg', [
'common',
'auth',
'validation',
'campaigns',
'irregularity',
])),
dehydratedState: dehydrate(client),
},
}
}
Example #4
Source File: [slug].tsx From frontend with MIT License | 6 votes |
getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const { slug } = ctx.query
const response = await securedProps(ctx, `/campaigns/donation/${slug}`)
const client = new QueryClient()
await client.prefetchQuery(`/campaign/${slug}`, queryFn)
if ('props' in response) {
return {
props: {
...response.props,
slug,
dehydratedState: dehydrate(client),
...(await serverSideTranslations(ctx.locale ?? 'bg', [
'common',
'auth',
'validation',
'campaigns',
'one-time-donation',
])),
},
}
}
return response
}
Example #5
Source File: index.tsx From frontend with MIT License | 6 votes |
getServerSideProps: GetServerSideProps = async (params) => {
const client = new QueryClient()
await client.prefetchQuery('/campaign/list', queryFn)
await prefetchCampaignTypesList(client)
return {
props: {
...(await serverSideTranslations(params.locale ?? 'bg', [
'common',
'auth',
'validation',
'campaigns',
])),
dehydratedState: dehydrate(client),
},
}
}