Skip to content

Commit

Permalink
chore: use function component on with-typescript example (vercel#12695)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubmit authored and rokinsky committed Jul 11, 2020
1 parent 623bb2a commit 9baf3b5
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions examples/with-typescript/pages/users/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,33 @@ type Props = {
errors?: string
}

export default class StaticPropsDetail extends React.Component<Props> {
render() {
const { item, errors } = this.props

if (errors) {
return (
<Layout title={`Error | Next.js + TypeScript Example`}>
<p>
<span style={{ color: 'red' }}>Error:</span> {errors}
</p>
</Layout>
)
}

const StaticPropsDetail: React.FunctionComponent<Props> = ({
item,
errors,
}) => {
if (errors) {
return (
<Layout
title={`${
item ? item.name : 'User Detail'
} | Next.js + TypeScript Example`}
>
{item && <ListDetail item={item} />}
<Layout title="Error | Next.js + TypeScript Example">
<p>
<span style={{ color: 'red' }}>Error:</span> {errors}
</p>
</Layout>
)
}

return (
<Layout
title={`${
item ? item.name : 'User Detail'
} | Next.js + TypeScript Example`}
>
{item && <ListDetail item={item} />}
</Layout>
)
}

export default StaticPropsDetail

export const getStaticPaths: GetStaticPaths = async () => {
// Get the paths we want to pre-render based on users
const paths = sampleUserData.map(user => ({
Expand Down

0 comments on commit 9baf3b5

Please sign in to comment.