diff --git a/readme.md b/readme.md
index b4ca4e69..32cfe527 100644
--- a/readme.md
+++ b/readme.md
@@ -77,9 +77,7 @@ After that, the file-system is the main API. Every `.js` file becomes a route th
Populate `./pages/index.js` inside your project:
```jsx
-export default () => (
-
Welcome to next.js!
-)
+export default () =>
Welcome to next.js!
```
and then just run `npm run dev` and go to `http://localhost:3000`. To use another port, you can run `npm run dev -- -p `.
@@ -99,9 +97,11 @@ Every `import` you declare gets bundled and served with each page. That means pa
```jsx
import cowsay from 'cowsay-browser'
-export default () => (
-
{ cowsay.say({ text: 'hi there!' }) }
-)
+
+export default () =>
+
+ {cowsay.say({ text: 'hi there!' })}
+
```
### CSS
@@ -116,7 +116,7 @@ export default () => (
We bundle [styled-jsx](https://github.com/zeit/styled-jsx) to provide support for isolated scoped CSS. The aim is to support "shadow CSS" similar to Web Components, which unfortunately [do not support server-rendering and are JS-only](https://github.com/w3c/webcomponents/issues/71).
```jsx
-export default () => (
+export default () =>
Hello world
scoped!
@@ -139,7 +139,6 @@ export default () => (
}
`}
-)
```
Please see the [styled-jsx documentation](https://www.npmjs.com/package/styled-jsx) for more examples.
@@ -156,9 +155,7 @@ Please see the [styled-jsx documentation](https://www.npmjs.com/package/styled-j
It's possible to use any existing CSS-in-JS solution. The simplest one is inline styles:
```jsx
-export default () => (
-
hi there
-)
+export default () =>
hi there
```
To use more sophisticated CSS-in-JS solutions, you typically have to implement style flushing for server-side rendering. We enable this by allowing you to define your own [custom ``](#user-content-custom-document) component that wraps each page
@@ -168,9 +165,7 @@ To use more sophisticated CSS-in-JS solutions, you typically have to implement s
Create a folder called `static` in your project root directory. From your code you can then reference those files with `/static/` URLs:
```jsx
-export default () => (
-
-)
+export default () =>
```
### Populating ``
@@ -187,7 +182,8 @@ We expose a built-in component for appending elements to the `` of the pag
```jsx
import Head from 'next/head'
-export default () => (
+
+export default () =>
My page title
@@ -195,7 +191,6 @@ export default () => (
Hello world!
-)
```
_Note: The contents of `` get cleared upon unmounting the component, so make sure each page completely defines what it needs in ``, without making assumptions about what other pages added_
@@ -211,16 +206,19 @@ When you need state, lifecycle hooks or **initial data population** you can expo
```jsx
import React from 'react'
+
export default class extends React.Component {
- static async getInitialProps ({ req }) {
- return req
- ? { userAgent: req.headers['user-agent'] }
- : { userAgent: navigator.userAgent }
+ static async getInitialProps({ req }) {
+ const userAgent = req ? req.headers['user-agent'] : navigator.userAgent
+ return { userAgent }
}
- render () {
- return
- Hello World {this.props.userAgent}
-
+
+ render() {
+ return (
+
+ Hello World {this.props.userAgent}
+
+ )
}
}
```
@@ -241,7 +239,10 @@ _Note: `getInitialProps` can **not** be used in children components. Only in `pa
You can also define the `getInitialProps` lifecycle method for stateless components:
```jsx
-const Page = ({ stars }) =>
Next stars: {stars}
+const Page = ({ stars }) =>
+
+ Next stars: {stars}
+
Page.getInitialProps = async ({ req }) => {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
@@ -278,16 +279,20 @@ Client-side transitions between routes can be enabled via a `` component.
```jsx
// pages/index.js
import Link from 'next/link'
-export default () => (
-
```
__Note: use [``](#prefetching-pages) for maximum performance, to link and prefetch in the background at the same time__
@@ -322,9 +327,15 @@ The component `` can also receive an URL object and it will automatically
```jsx
// pages/index.js
import Link from 'next/link'
-export default () => (
-
```
That will generate the URL string `/about?name=Zeit`, you can use every property as defined in the [Node.js URL module documentation](https://nodejs.org/api/url.html#url_url_strings_and_url_objects).
@@ -336,9 +347,15 @@ The default behaviour for the `` component is to `push` a new url into the
```jsx
// pages/index.js
import Link from 'next/link'
-export default () => (
-
```
##### Using a component that support `onClick`
@@ -348,24 +365,30 @@ export default () => (
```jsx
// pages/index.js
import Link from 'next/link'
-export default () => (
-
)
}
}
@@ -863,7 +901,7 @@ For custom advanced behavior of Next.js, you can create a `next.config.js` in th
Note: `next.config.js` is a regular Node.js module, not a JSON file. It gets used by the Next server and build phases, and not included in the browser build.
-```javascript
+```js
// next.config.js
module.exports = {
/* config options here */
@@ -874,7 +912,7 @@ module.exports = {
You can specify a name to use for a custom build directory. For example, the following config will create a `build` folder instead of a `.next` folder. If no configuration is specified then next will create a `.next` folder.
-```javascript
+```js
// next.config.js
module.exports = {
distDir: 'build'
@@ -902,7 +940,7 @@ module.exports = {
// Important: return the modified config
return config
},
- webpackDevMiddleware: (config) => {
+ webpackDevMiddleware: config => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
@@ -928,12 +966,9 @@ This is designed so that you are not surprised by modifications we could make to
Here's an example `.babelrc` file:
-```js
+```json
{
- "presets": [
- "next/babel",
- "stage-0"
- ],
+ "presets": ["next/babel", "stage-0"]
}
```
@@ -998,15 +1033,15 @@ Simply develop your app as you normally do with Next.js. Then create a custom Ne
```js
// next.config.js
module.exports = {
- exportPathMap: function () {
+ exportPathMap: function() {
return {
- "/": { page: "/" },
- "/about": { page: "/about" },
- "/p/hello-nextjs": { page: "/post", query: { title: "hello-nextjs" } },
- "/p/learn-nextjs": { page: "/post", query: { title: "learn-nextjs" } },
- "/p/deploy-nextjs": { page: "/post", query: { title: "deploy-nextjs" } }
+ '/': { page: '/' },
+ '/about': { page: '/about' },
+ '/p/hello-nextjs': { page: '/post', query: { title: 'hello-nextjs' } },
+ '/p/learn-nextjs': { page: '/post', query: { title: 'learn-nextjs' } },
+ '/p/deploy-nextjs': { page: '/post', query: { title: 'deploy-nextjs' } }
}
- },
+ }
}
```
@@ -1023,9 +1058,9 @@ For that you may need to add a NPM script to `package.json` like this:
```json
{
- "scripts": {
- "build": "next build && next export"
- }
+ "scripts": {
+ "build": "next build && next export"
+ }
}
```