Skip to content

Commit 4508dcb

Browse files
committed
refactor: some simplifications
1 parent a1f6568 commit 4508dcb

1 file changed

Lines changed: 4 additions & 26 deletions

File tree

  • examples/nextjs/template-hierarchy/src/pages

examples/nextjs/template-hierarchy/src/pages/[...uri].js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,21 @@ import availableTemplates from '@/wp-templates';
88
export default function Page(props) {
99
const { templateData } = props;
1010

11-
if (!templateData?.template?.id) {
12-
return (
13-
<div style={{ padding: '20px', textAlign: 'center' }}>
14-
<h1 style={{ color: 'red' }}>Template not found</h1>
15-
<p>No template could be resolved for this URI.</p>
16-
</div>
17-
);
18-
}
19-
20-
const PageTemplate = availableTemplates[templateData.template.id];
21-
22-
if (!PageTemplate) {
23-
return (
24-
<div style={{ padding: '20px', textAlign: 'center' }}>
25-
<h1 style={{ color: 'red' }}>Component not found</h1>
26-
<p>Template "{templateData.template.id}" is not available.</p>
27-
<pre
28-
style={{ textAlign: 'left', background: '#f5f5f5', padding: '10px' }}>
29-
{JSON.stringify(templateData, null, 2)}
30-
</pre>
31-
</div>
32-
);
33-
}
11+
const PageTemplate = availableTemplates[templateData?.template?.id];
3412

3513
return <PageTemplate {...props} />;
3614
}
3715

3816
export async function getServerSideProps(context) {
3917
const { params } = context;
4018

19+
const client = createDefaultClient(process.env.WORDPRESS_URL);
20+
setGraphQLClient(client);
21+
4122
const uri = Array.isArray(params?.uri)
4223
? '/' + params.uri.join('/') + '/'
4324
: '/';
4425

45-
const client = createDefaultClient(process.env.WORDPRESS_URL);
46-
setGraphQLClient(client);
47-
4826
try {
4927
const templateData = await uriToTemplate({
5028
uri,

0 commit comments

Comments
 (0)