Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 55ddfd2

Browse files
committed
Move error check to static props fn
1 parent 3b8660d commit 55ddfd2

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

api/wordpress/_global/getPostTypeStaticProps.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,22 @@ export default async function getPostTypeStaticProps(
4545
slug
4646
)
4747

48+
const props = {
49+
post,
50+
error,
51+
errorMessage
52+
}
53+
54+
// Custom handling for homepage.
55+
if (error) {
56+
// Fallback to empty props if homepage not set in WP.
57+
props.post = null
58+
props.error = false
59+
}
60+
4861
// Merge in query results as Apollo state.
4962
return addApolloState(apolloClient, {
50-
props: {
51-
post,
52-
error,
53-
errorMessage
54-
},
63+
props,
5564
revalidate: 60 * 5
5665
})
5766
}

pages/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,7 @@ export default function HomePage({post}) {
4848
* @return {Object} Post props.
4949
*/
5050
export async function getStaticProps() {
51-
const props = await getPostTypeStaticProps({slug: '/'}, postType)
52-
53-
return !props.props.error
54-
? props
55-
: // Fallback to empty props if homepage not set in WP.
56-
{
57-
props: {
58-
post: null
59-
}
60-
}
51+
return await getPostTypeStaticProps({slug: '/'}, postType)
6152
}
6253

6354
HomePage.propTypes = {

0 commit comments

Comments
 (0)