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

Update examples to use getStaticProps where possible #11136

Merged
merged 33 commits into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d9096e6
Remove micro example
timneutkens Mar 17, 2020
4f2c994
Remove page that uses getInitialProps
timneutkens Mar 17, 2020
2c2e90d
Update with-docker example
timneutkens Mar 17, 2020
027dfc9
Update dynamic import example
timneutkens Mar 17, 2020
33013e1
Update Fela example
timneutkens Mar 17, 2020
3d64ac6
Update Flow example
timneutkens Mar 17, 2020
b0ae996
Update framer motion example
timneutkens Mar 17, 2020
a12527f
Remove freactal example
timneutkens Mar 17, 2020
93e57ff
Remove with-higher-order-component
timneutkens Mar 17, 2020
8941f56
Remove with-immutable-redux-wrapper as it shows avenues to performanc…
timneutkens Mar 17, 2020
519d337
Remove example that doesn't have usage
timneutkens Mar 17, 2020
62cabbc
Update with-kea
timneutkens Mar 17, 2020
fa81a65
Remove example that is not used
timneutkens Mar 17, 2020
785ebc4
Update next-page-transitions example
timneutkens Mar 17, 2020
0eedf58
Remove next-routes example as dynamic routes are supported by default
timneutkens Mar 17, 2020
6d85516
Add link to documentation
timneutkens Mar 17, 2020
53e4937
Update Overmind example
timneutkens Mar 17, 2020
9363c99
Update pretty-url-routing example
timneutkens Mar 17, 2020
497aa11
Remove update with low usage
timneutkens Mar 17, 2020
53a741c
Update with-react-ga example
timneutkens Mar 17, 2020
e3888b8
Update React Helmet example
timneutkens Mar 17, 2020
e7d4e95
Remove mobile-detect from carousel example
timneutkens Mar 17, 2020
b82ec6f
Remove react-useragent as it shows a bad practice
timneutkens Mar 17, 2020
10e5440
Remove react-uwp example as it has low usage
timneutkens Mar 17, 2020
3265644
Remove recompose example as it shows outdated practices
timneutkens Mar 17, 2020
4f48668
Remove refnux example as it has low usage
timneutkens Mar 17, 2020
4445151
Remove example that can be created using api routes
timneutkens Mar 17, 2020
5e9e540
Update with-segment-analytics
timneutkens Mar 17, 2020
a1ce20a
Update socket.io example
timneutkens Mar 17, 2020
79a5c9c
Remove socket.io example as it's shows bad practices
timneutkens Mar 17, 2020
26a1848
Update static export example
timneutkens Mar 17, 2020
2fe8cd8
Update universal configuration example
timneutkens Mar 17, 2020
1643a85
Merge branch 'canary' of github.com:zeit/next.js into docs/update-exa…
timneutkens Mar 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 0 additions & 42 deletions examples/api-routes-micro/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions examples/api-routes-micro/package.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/api-routes-micro/pages/api/posts.js

This file was deleted.

18 changes: 0 additions & 18 deletions examples/api-routes-micro/pages/index.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/using-router/components/Header.js
Expand Up @@ -4,7 +4,6 @@ export default () => (
<div>
<Link href="/">Home</Link>
<Link href="/about">About</Link>
<Link href="/error">Error</Link>
</div>
)

Expand Down
19 changes: 0 additions & 19 deletions examples/using-router/pages/error.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/with-docker/README.md
Expand Up @@ -47,14 +47,7 @@ Run the docker image:
```bash
docker run --rm -it \
-p 3000:3000 \
-e "API_URL=https://example.com" \
next-app
```

or use `yarn build-docker-multistage`

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
now --docker -e API_URL="https://example.com"
```
11 changes: 0 additions & 11 deletions examples/with-docker/next.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion examples/with-docker/package.json
Expand Up @@ -7,7 +7,7 @@
"start": "next start",
"build-docker": "docker build -t next-app .",
"build-docker-multistage": "docker build -t next-app -f ./Dockerfile.multistage .",
"run-docker": "docker run --rm -it -p 3000:3000 -e 'API_URL=https://example.com' next-app"
"run-docker": "docker run --rm -it -p 3000:3000 next-app"
},
"dependencies": {
"next": "latest",
Expand Down
15 changes: 2 additions & 13 deletions examples/with-docker/pages/index.js
@@ -1,16 +1,5 @@
import React from 'react'
import getConfig from 'next/config'
const { publicRuntimeConfig } = getConfig()

const { API_URL } = publicRuntimeConfig

export default class extends React.Component {
static async getInitialProps() {
// fetch(`${API_URL}/some-path`)
return {}
}

render() {
return <div>The API_URL is {API_URL}</div>
}
export default () => {
return <h1>Hello World!</h1>
}
2 changes: 1 addition & 1 deletion examples/with-dynamic-import/components/hello1.js
@@ -1 +1 @@
export default () => <p>Hello World 1 (imported dynamiclly) </p>
export default () => <p>Hello World 1 (imported dynamically) </p>
2 changes: 1 addition & 1 deletion examples/with-dynamic-import/components/hello2.js
@@ -1 +1 @@
export default () => <p>Hello World 2 (imported dynamiclly) </p>
export default () => <p>Hello World 2 (imported dynamically) </p>
2 changes: 1 addition & 1 deletion examples/with-dynamic-import/components/hello3.js
@@ -1 +1 @@
export default () => <p>Hello World 3 (imported dynamiclly) </p>
export default () => <p>Hello World 3 (imported dynamically) </p>
2 changes: 1 addition & 1 deletion examples/with-dynamic-import/components/hello4.js
@@ -1 +1 @@
export default () => <p>Hello World 4 (imported dynamiclly) </p>
export default () => <p>Hello World 4 (imported dynamically) </p>
2 changes: 1 addition & 1 deletion examples/with-dynamic-import/components/hello5.js
@@ -1 +1 @@
export default () => <p>Hello World 5 (imported dynamiclly) </p>
export default () => <p>Hello World 5 (imported dynamically) </p>
53 changes: 20 additions & 33 deletions examples/with-dynamic-import/pages/index.js
@@ -1,39 +1,30 @@
import React from 'react'
import { useRouter } from 'next/router'
import React, { useState } from 'react'
import Header from '../components/Header'
import dynamic from 'next/dynamic'

const DynamicComponent1 = dynamic(import('../components/hello1'))
const DynamicComponent1 = dynamic(() => import('../components/hello1'))

const DynamicComponent2WithCustomLoading = dynamic({
loader: () => import('../components/hello2'),
loading: () => <p>Loading caused by client page transition ...</p>,
})

const DynamicComponent3WithNoSSR = dynamic({
loader: () => import('../components/hello3'),
loading: () => <p>Loading ...</p>,
ssr: false,
})
const DynamicComponent2WithCustomLoading = dynamic(
() => import('../components/hello2'),
{
loading: () => <p>Loading caused by client page transition ...</p>,
}
)

const DynamicComponent4 = dynamic({
loader: () => import('../components/hello4'),
})
const DynamicComponent3WithNoSSR = dynamic(
() => import('../components/hello3'),
{
loading: () => <p>Loading ...</p>,
ssr: false,
}
)

const DynamicComponent5 = dynamic({
loader: () => import('../components/hello5'),
})
const DynamicComponent4 = dynamic(() => import('../components/hello4'))

const IndexPage = ({ showMore }) => {
const router = useRouter()
const handleToggle = () => {
if (showMore) {
router.push('/')
return
}
const DynamicComponent5 = dynamic(() => import('../components/hello5'))

router.push('/?showMore=1')
}
const IndexPage = () => {
const [showMore, setShowMore] = useState(false)

return (
<div>
Expand All @@ -53,13 +44,9 @@ const IndexPage = ({ showMore }) => {

{/* Load on demand */}
{showMore && <DynamicComponent5 />}
<button onClick={handleToggle}>Toggle Show More</button>
<button onClick={() => setShowMore(!showMore)}>Toggle Show More</button>
</div>
)
}

IndexPage.getInitialProps = ({ query }) => {
return { showMore: Boolean(query.showMore) }
}

export default IndexPage
29 changes: 8 additions & 21 deletions examples/with-fela/pages/_app.js
@@ -1,24 +1,11 @@
import App from 'next/app'
import React from 'react'
import FelaProvider from '../FelaProvider'

export default class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {}

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}

return { pageProps }
}

render() {
const { Component, pageProps, renderer } = this.props
return (
<FelaProvider renderer={renderer}>
<Component {...pageProps} />
</FelaProvider>
)
}
function MyApp({ Component, pageProps, renderer }) {
return (
<FelaProvider renderer={renderer}>
<Component {...pageProps} />
</FelaProvider>
)
}

export default MyApp
60 changes: 24 additions & 36 deletions examples/with-flow/pages/_app.js
@@ -1,42 +1,30 @@
import App from 'next/app'
import Link from 'next/link'
import React from 'react'

export default class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {}
function MyApp({ Component, pageProps }) {
return (
<>
<header>
<nav>
<Link href="/">
<a>Home</a>
</Link>
|
<Link href="/about">
<a>About</a>
</Link>
|
<Link href="/contact">
<a>Contact</a>
</Link>
</nav>
</header>

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
<Component {...pageProps} />

return { pageProps }
}

render() {
const { Component, pageProps } = this.props
return (
<>
<header>
<nav>
<Link href="/">
<a>Home</a>
</Link>
|
<Link href="/about">
<a>About</a>
</Link>
|
<Link href="/contact">
<a>Contact</a>
</Link>
</nav>
</header>

<Component {...pageProps} />

<footer>I`m here to stay</footer>
</>
)
}
<footer>I`m here to stay</footer>
</>
)
}

export default MyApp
2 changes: 1 addition & 1 deletion examples/with-framer-motion/components/Gallery.js
Expand Up @@ -33,7 +33,7 @@ const Thumbnail = ({ id, i }) => (
variants={frameVariants}
transition={transition}
>
<Link href="/image/[id]" as={`/image/${i}`} scroll={false}>
<Link href="/image/[index]" as={`/image/${i}`} scroll={false}>
<motion.img
src={`https://static1.squarespace.com/static/5b475b2c50a54f54f9b4e1dc/t/${id}.jpg?format=1500w`}
alt="The Barbican"
Expand Down
4 changes: 2 additions & 2 deletions examples/with-framer-motion/components/SingleImage.js
Expand Up @@ -23,12 +23,12 @@ const backVariants = {
enter: { x: 0, opacity: 1, transition: { delay: 1, ...transition } },
}

const SingleImage = ({ id }) => (
const SingleImage = ({ index }) => (
<>
<motion.div className="single" initial="exit" animate="enter" exit="exit">
<motion.img
variants={imageVariants}
src={`https://static1.squarespace.com/static/5b475b2c50a54f54f9b4e1dc/t/${images[id]}.jpg?format=1500w`}
src={`https://static1.squarespace.com/static/5b475b2c50a54f54f9b4e1dc/t/${images[index]}.jpg?format=1500w`}
alt="The Barbican"
/>
<motion.div className="back" variants={backVariants}>
Expand Down