next#GetStaticPropsResult TypeScript Examples
The following examples show how to use
next#GetStaticPropsResult.
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: index.tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export async function getStaticProps({
params,
}: GetStaticPropsContext<ProfileParams>): Promise<
GetStaticPropsResult<Omit<ProfileLayoutProps, 'children'>>
> {
const { userId } = params;
try {
const profile = await getProfileSSR(userId);
return {
props: {
profile,
},
revalidate: 60,
};
} catch (err) {
if ('message' in err && err.message === 'not found') {
return {
props: { profile: null },
revalidate: 60,
};
}
throw err;
}
}
Example #2
Source File: [value].tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export async function getStaticProps({
params,
}: GetStaticPropsContext<KeywordParams>): Promise<
GetStaticPropsResult<KeywordPageProps>
> {
const { value } = params;
return {
props: {
keyword: value,
},
revalidate: 60,
};
}
Example #3
Source File: [id].tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export async function getStaticProps({
params,
}: GetStaticPropsContext<PostParams>): Promise<GetStaticPropsResult<Props>> {
const { id } = params;
try {
const postData = await request<PostData>(
`${apiUrl}/graphql`,
POST_BY_ID_STATIC_FIELDS_QUERY,
{ id },
);
return {
props: {
id,
postData,
},
revalidate: 60,
};
} catch (err) {
const clientError = err as ClientError;
if (clientError?.response?.errors?.[0]?.extensions?.code === 'NOT_FOUND') {
return {
props: { id: null },
revalidate: 60,
};
}
throw err;
}
}
Example #4
Source File: [source].tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export async function getStaticProps({
params,
}: GetStaticPropsContext<SourcePageParams>): Promise<
GetStaticPropsResult<SourcePageProps>
> {
try {
const res = await request<SourceData>(`${apiUrl}/graphql`, SOURCE_QUERY, {
id: params.source,
});
return {
props: {
source: res.source,
},
revalidate: 60,
};
} catch (err) {
if (err?.response?.errors?.[0].extensions.code === 'NOT_FOUND') {
return {
props: {
source: null,
},
revalidate: 60,
};
}
throw err;
}
}
Example #5
Source File: [tag].tsx From apps with GNU Affero General Public License v3.0 | 6 votes |
export function getStaticProps({
params,
}: GetStaticPropsContext<TagPageParams>): GetStaticPropsResult<TagPageProps> {
return {
props: {
tag: params.tag,
},
};
}
Example #6
Source File: apolloClient.ts From next-page-tester with MIT License | 6 votes |
export function addApolloState<P>(
client: ApolloClient<NormalizedCacheObject>,
pageProps: GetStaticPropsResult<P>
) {
// @ts-expect-error just checking
if (pageProps.props) {
// @ts-expect-error injected prop
pageProps.props[APOLLO_STATE_PROP_NAME] = client.cache.extract();
}
return pageProps;
}
Example #7
Source File: index.tsx From webping.cloud with MIT License | 5 votes |
export async function getStaticProps(): Promise<GetStaticPropsResult<CloudPingProps>> {
const providers = getAllProviders()
const regions = getAllCloudRegions()
const initialState: LatencyState = {}
for (const provider of providers) {
for (const region of regions[provider.key]) {
const key = `${provider.key}-${region.key}`
initialState[key] = {
key,
provider,
region,
}
}
}
return {
props: {
initialState,
providers,
geos: Object.values(regions).reduce((prev, curr) => {
for (const region of curr) {
if (!prev[region.geo]) {
prev[region.geo] = []
}
if (!prev[region.geo].includes(region.country)) {
prev[region.geo] = [...prev[region.geo], region.country]
}
}
return prev
}, {} as Record<string, string[]>),
countries: Object.values(regions).reduce((prev, curr) => {
for (const region of curr) {
if (!prev.includes(region.country)) {
prev = [...prev, region.country]
}
}
return prev
}, [] as string[]),
},
}
}
Example #8
Source File: getPropsWrapper.ts From Cromwell with MIT License | 4 votes |
wrapGetProps = (pageName: TDefaultPageName | string,
originalGet: ((context: TStaticPageContext) => any) | null,
getType: 'getServerSideProps' | 'getInitialProps' | 'getStaticProps'
): TGetStaticProps<TCromwellPageCoreProps> => {
if (pageName === '/') pageName = 'index';
if (pageName.startsWith('/')) pageName = pageName.slice(1, pageName.length - 1);
const getStaticWrapper: TGetStaticProps<TCromwellPageCoreProps> = async (context) => {
let rendererData: {
pageConfig?: TPageConfig;
pluginsSettings?: TPluginsSettings;
themeConfig?: TThemeConfig;
userConfig?: TThemeConfig;
cmsSettings?: TCmsConfig;
themeCustomConfig?: any;
pagesInfo?: TPageInfo[];
} = {};
if (!process.env.THEME_NAME) {
throw new Error('Cromwell:getPropsWrapper: `THEME_NAME` was not found in process.env')
}
try {
rendererData = (await getRestApiClient().getRendererRage(pageName,
process.env.THEME_NAME, String(context?.params?.slug))) ?? {};
} catch (e) {
console.error(e);
}
const { pageConfig, themeConfig, cmsSettings,
themeCustomConfig, pluginsSettings, userConfig } = rendererData;
const pageConfigRoute = pageConfig?.route;
if (themeConfig?.defaultPages) setStoreItem('defaultPages', themeConfig?.defaultPages);
const resolvedPageRoute = resolvePageRoute(pageName, { slug: context?.params?.slug as string })
if (themeConfig) {
themeConfig.palette = Object.assign({}, themeConfig.palette,
userConfig?.palette);
}
context.pageConfig = rendererData.pageConfig;
context.themeConfig = rendererData.themeConfig;
context.userConfig = rendererData.userConfig;
context.cmsSettings = rendererData.cmsSettings;
context.themeCustomConfig = rendererData.themeCustomConfig;
context.pagesInfo = rendererData.pagesInfo;
const childStaticProps = await getThemeStaticProps(pageName, originalGet, context);
const extraPlugins = childStaticProps?.extraPlugins;
if (childStaticProps?.extraPlugins) delete childStaticProps?.extraPlugins;
const plugins = await pluginsDataFetcher(pageConfigRoute, context, pluginsSettings,
extraPlugins);
const pluginsNextProps = Object.assign({}, ...Object.values(plugins)
.map(plugin => plugin.nextProps).filter(Boolean));
if (childStaticProps && !childStaticProps.props) childStaticProps.props = {};
const cmsProps: TPageCmsProps = {
plugins,
pageConfig,
cmsSettings,
themeCustomConfig,
pageConfigRoute,
resolvedPageRoute,
slug: context?.params?.slug,
defaultPages: themeConfig?.defaultPages,
themeHeadHtml: themeConfig?.headHtml,
themeFooterHtml: themeConfig?.footerHtml,
palette: themeConfig?.palette,
}
const pageProps: GetStaticPropsResult<TCromwellPageCoreProps> = {
...childStaticProps,
...pluginsNextProps,
props: {
...(childStaticProps.props ?? {}),
cmsProps: cmsProps
}
}
if (getType === 'getStaticProps') {
pageProps.revalidate = childStaticProps?.revalidate ?? 60;
}
return removeUndefined(pageProps);
}
return getStaticWrapper;
}