Skip to content

Instantly share code, notes, and snippets.

@charliewilco
Last active March 6, 2018 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charliewilco/8d94afbfc3b939c9befebb532e55aa3f to your computer and use it in GitHub Desktop.
Save charliewilco/8d94afbfc3b939c9befebb532e55aa3f to your computer and use it in GitHub Desktop.
After.js
import React, { Component, Fragment } from 'react'
import 'universal-fetch'
export default class extends Component {
static async getInitialProps({ match, prefetch }) {
const { user, repo } = match.params
const response = await fetch(`https://api.github.com/repos/${user}/${repo}`)
const post = await response.json()
return { post, user, repo };
}
render() {
const { post } = this.props
return (
<article style={{ padding: 16, marginLeft: 'auto', marginRight: 'auto', maxWidth: 528 }}>
{
post ? (
<Fragment>
<header>
<h3>{post.name}</h3>
<h4>{post.language}</h4>
<time>{post.created_at}</time>
</header>
<section>
<ul>
<li>Open Issues: {post.open_issues_count}</li>
<li>Forks: {post.forks_count}</li>
</ul>
</section>
</Fragment>
) : <h1>Loading</h1>
}
</article>
)
}
}
import React, { Component, Fragment } from 'react'
import 'universal-fetch'
export default class extends Component {
static async getInitialProps({ match, prefetch }) {
const { user, repo } = match.params
const response = await fetch(`https://api.github.com/repos/${user}/${repo}`)
const post = await response.json()
return {
post,
user,
repo
};
}
render() {
const { post } = this.props
return (
<article style={{ padding: 16, marginLeft: 'auto', marginRight: 'auto', maxWidth: 528 }}>
{
post ? (
<Fragment>
<header>
<h3>{post.name}</h3>
<h4>{post.language}</h4>
<time>{post.created_at}</time>
</header>
<section>
<ul>
<li>Open Issues: {post.open_issues_count}</li>
<li>Forks: {post.forks_count}</li>
</ul>
</section>
</Fragment>
) : <h1>Loading</h1>
}
</article>
)
}
}
import React from 'react';
import { asyncComponent } from '@jaredpalmer/after';
export default [
{
path: '/',
exact: true,
component: asyncComponent({
loader: () => import('./Home'),
Placeholder: () => <div>...LOADING...</div>
}),
},
{
path: '/:user/:repo',
component: asyncComponent({
loader: () => import('./Content')
Placeholder: () => <div>...LOADING...</div>
})
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment