Skip to content

Commit

Permalink
Update examples to use getStaticProps where possible (#11136)
Browse files Browse the repository at this point in the history
* Remove micro example

* Remove page that uses getInitialProps

* Update with-docker example

* Update dynamic import example

* Update Fela example

* Update Flow example

* Update framer motion example

* Remove freactal example

* Remove with-higher-order-component

* Remove with-immutable-redux-wrapper as it shows avenues to performance issues

* Remove example that doesn't have usage

* Update with-kea

* Remove example that is not used

* Update next-page-transitions example

* Remove next-routes example as dynamic routes are supported by default

* Add link to documentation

* Update Overmind example

* Update pretty-url-routing example

* Remove update with low usage

* Update with-react-ga example

* Update React Helmet example

* Remove mobile-detect from carousel example

* Remove react-useragent as it shows a bad practice

* Remove react-uwp example as it has low usage

* Remove recompose example as it shows outdated practices

* Remove refnux example as it has low usage

* Remove example that can be created using api routes

* Update with-segment-analytics

* Update socket.io example

* Remove socket.io example as it's shows bad practices

* Update static export example

* Update universal configuration example
  • Loading branch information
timneutkens committed Mar 17, 2020
1 parent bfab990 commit 7e2d476
Show file tree
Hide file tree
Showing 180 changed files with 359 additions and 4,586 deletions.
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

0 comments on commit 7e2d476

Please sign in to comment.