Skip to content

Commit 1e77568

Browse files
jagreehalrauchg
authored andcommitted
added example with flow (#814)
* added example with flow * Fixed linting errors
1 parent 43149bd commit 1e77568

File tree

9 files changed

+122
-0
lines changed

9 files changed

+122
-0
lines changed

examples/with-flow/.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"next/babel"
4+
],
5+
"plugins": [
6+
"transform-flow-strip-types"
7+
]
8+
}

examples/with-flow/.flowconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ignore]
2+
3+
[include]
4+
5+
[libs]
6+
7+
[options]

examples/with-flow/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example app with [Flow](https://flowtype.org/)
2+
3+
## How to use
4+
5+
Download the example [or clone the repo](https://github.com/zeit/next.js):
6+
7+
```bash
8+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-styled-components
9+
cd with-flow
10+
```
11+
12+
Install it and run:
13+
14+
```bash
15+
npm install
16+
npm run dev
17+
```
18+
19+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
20+
21+
```bash
22+
now
23+
```
24+
25+
## The idea behind the example
26+
27+
This example shows how you can use Flow, with the transform-flow-strip-types babel plugin stripping flow type annotations from your output code.
28+
29+
![with-flow](with-flow.gif)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @flow
2+
3+
import type {Element} from 'React'
4+
import Link from 'next/link'
5+
import Head from 'next/head'
6+
7+
type Props = {
8+
children?: Element<any>,
9+
title?: string
10+
}
11+
12+
export default ({children, title = 'This is the default title'}: Props) => (
13+
<div>
14+
<Head>
15+
<title>{title}</title>
16+
<meta charSet='utf-8' />
17+
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
18+
</Head>
19+
<header>
20+
<nav>
21+
<Link href='/'><a>Home</a></Link>|
22+
<Link href='/about'><a>About</a></Link>|
23+
<Link href='/contact'><a>Contact</a></Link>
24+
</nav>
25+
</header>
26+
{children}
27+
<footer>
28+
I`m here to stay
29+
</footer>
30+
</div>
31+
)

examples/with-flow/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "with-flow",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"author": "Jag Reehal",
6+
"scripts": {
7+
"dev": "next",
8+
"build": "next build",
9+
"flow": "flow; test $? -eq 0 -o $? -eq 2",
10+
"start": "next start"
11+
},
12+
"dependencies": {
13+
"next": "^2.0.0-beta"
14+
},
15+
"devDependencies": {
16+
"babel-eslint": "^7.1.1",
17+
"babel-plugin-transform-flow-strip-types": "^6.21.0",
18+
"flow-bin": "^0.37.4"
19+
}
20+
}

examples/with-flow/pages/about.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
3+
import Layout from '../components/layout'
4+
5+
export default () => (
6+
<Layout title='About us'>
7+
<div>About us</div>
8+
</Layout>
9+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
3+
import Layout from '../components/layout'
4+
5+
export default () => (
6+
<Layout title='Contact us'>
7+
<div>Contact</div>
8+
</Layout>
9+
)

examples/with-flow/pages/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
3+
import Layout from '../components/layout'
4+
5+
export default () => (
6+
<Layout>
7+
<div>Hello World.</div>
8+
</Layout>
9+
)

examples/with-flow/with-flow.gif

264 KB
Loading

0 commit comments

Comments
 (0)