-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' of github.com:zeit/next.js into canary
- Loading branch information
Showing
14 changed files
with
49 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import fetch from 'isomorphic-unfetch' | ||
import useSwr from 'swr' | ||
import Link from 'next/link' | ||
|
||
const Index = ({ users }) => ( | ||
<ul> | ||
{users.map(user => ( | ||
<li key={user.id}> | ||
<Link href="/user/[id]" as={`/user/${user.id}`}> | ||
<a>{`User ${user.id}`}</a> | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
const fetcher = url => fetch(url).then(res => res.json()) | ||
|
||
Index.getInitialProps = async () => { | ||
const response = await fetch('http://localhost:3000/api/users') | ||
const users = await response.json() | ||
export default function Index() { | ||
const { data, error } = useSwr('/api/users', fetcher) | ||
|
||
return { users } | ||
} | ||
if (error) return <div>Failed to load users</div> | ||
if (!data) return <div>Loading...</div> | ||
|
||
export default Index | ||
return ( | ||
<ul> | ||
{data.map(user => ( | ||
<li key={user.id}> | ||
<Link href="/user/[id]" as={`/user/${user.id}`}> | ||
<a>{`User ${user.id}`}</a> | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import fetch from 'isomorphic-unfetch' | ||
import { useRouter } from 'next/router' | ||
import useSwr from 'swr' | ||
|
||
const User = ({ user }) => <div>{user.name}</div> | ||
const fetcher = url => fetch(url).then(res => res.json()) | ||
|
||
User.getInitialProps = async ({ query: { id } }, res) => { | ||
const response = await fetch(`http://localhost:3000/api/user/${id}`) | ||
const user = await response.json() | ||
export default function User() { | ||
const router = useRouter() | ||
const { data, error } = useSwr(`/api/user/${router.query.id}`, fetcher) | ||
|
||
return { user } | ||
} | ||
if (error) return <div>Failed to load user</div> | ||
if (!data) return <div>Loading...</div> | ||
|
||
export default User | ||
return <div>{data.name}</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist/ | ||
node_modules/ | ||
|
||
# Firebase cache | ||
.firebase/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters