Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated analyze-bundles example #11031

Merged
merged 2 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/analyze-bundles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"cross-env": "^6.0.3",
"faker": "^4.1.0",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
"react": "^16.8.0",
"react-dom": "^16.8.0"
},
"license": "ISC"
}
45 changes: 21 additions & 24 deletions examples/analyze-bundles/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import React from 'react'
import Link from 'next/link'
import faker from 'faker'

export default class Index extends React.Component {
static getInitialProps({ req }) {
if (req) {
// Runs only in the server
const faker = require('faker')
const name = faker.name.findName()
return { name }
}

// Runs only in the client
return { name: 'Arunoda' }
}

render() {
const { name } = this.props
return (
const Index = ({ name }) => {
return (
<div>
<h1>Home Page</h1>
<p>Welcome, {name}</p>
<div>
<h1>Home Page</h1>
<p>Welcome, {name}</p>
<div>
<Link href="/about">
<a>About Page</a>
</Link>
</div>
<Link href="/about">
<a>About Page</a>
</Link>
</div>
)
</div>
)
}

export default Index

export async function getStaticProps() {
// The name will be generated at build time only
const name = faker.name.findName()

return {
props: { name },
}
}