KEMBAR78
React Server Side Rendering with Next.js
!
PATENTS
What's Next.js for React?
Jamie Barton
@notrab
@norseal
Ruby on Rails
JavaScript
React dot js
Redux
GraphQL
zeit/next.js
create-react-app?
Core features of NextJS
Hot code reloading
Automatic code splitting
File system based routing
Convention over configuration
Server Side Rendering
Easy to deploy
Hot code reloading
Automatic code splitting
File system based routing
Convention over configuration
Server Side Rendering
Easy to deploy
SSR + SEO = ❤
💔
😱
SSR TTFB is slower than CSR
📈
File system based routing
yarn init -y
yarn add next@latest
yarn add next@latest react react-dom
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
}
./pages
./pages/index.js
export default () => <h1>Hello world!</h1>
yarn dev
./pages/about.js
export default () => <h1>About us</h1>
Routing
import Link from 'next/link'
Example: Layout
./components/layout.js
import Link from 'next/link'
export default ({ children }) =>
<div>
<nav>
<Link href="/">Home</Link> &middot;
<Link href="/about">About</Link>
</nav>
<main>
{children}
</main>
<footer>
&copy; 2017
</footer>
</div>
<Link href="/about">About</Link>
export default () => <h1>Hello world!</h1>
import Layout from '../components/layout'
export default () =>
<Layout>
<h1>Hello world!</h1>
</Layout>
export default () => <h1>About us</h1>
import Layout from '../components/layout'
export default () =>
<Layout>
<h1>About us</h1>
</Layout>
Script Preloading
<Link href="/about">About</Link>
<Link href="/about" prefetch>About</Link>
Data Fetching
async getInitialProps()
Page.getInitialProps = async ({ req }) => {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const json = await res.json()
return { stars: json.stargazers_count }
}
Easy to deploy
npm install -g now
now
next build && next export
Custom Babel config
Custom Webpack config
Custom server logic
CSS-in-JS
But what about…?
github.com/zeit/next.js
🤔

React Server Side Rendering with Next.js