2017-04-17 15:33:40 +00:00
|
|
|
import React from 'react'
|
2017-06-16 13:19:34 +00:00
|
|
|
import Router from 'next/router'
|
2017-04-17 15:33:40 +00:00
|
|
|
import Header from '../components/Header'
|
|
|
|
import Counter from '../components/Counter'
|
2017-04-17 20:15:50 +00:00
|
|
|
import dynamic from 'next/dynamic'
|
2017-04-27 15:22:25 +00:00
|
|
|
import { asyncReactor } from 'async-reactor'
|
2017-04-17 15:33:40 +00:00
|
|
|
|
2017-04-18 16:37:57 +00:00
|
|
|
const DynamicComponent = dynamic(import('../components/hello1'))
|
|
|
|
const DynamicComponentWithCustomLoading = dynamic(
|
|
|
|
import('../components/hello2'),
|
|
|
|
{
|
|
|
|
loading: () => (<p>...</p>)
|
|
|
|
}
|
|
|
|
)
|
2017-04-18 16:51:31 +00:00
|
|
|
const DynamicComponentWithNoSSR = dynamic(
|
|
|
|
import('../components/hello3'),
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
2017-04-27 15:22:25 +00:00
|
|
|
const DynamicComponentWithAsyncReactor = asyncReactor(async () => {
|
|
|
|
const Hello4 = await import('../components/hello4')
|
|
|
|
return (<Hello4 />)
|
|
|
|
})
|
2017-04-17 15:33:40 +00:00
|
|
|
|
2017-05-15 04:44:26 +00:00
|
|
|
const DynamicComponent5 = dynamic(import('../components/hello5'))
|
|
|
|
|
2017-06-16 13:19:34 +00:00
|
|
|
const DynamicBundle = dynamic({
|
|
|
|
modules: (props) => {
|
|
|
|
const components = {
|
|
|
|
Hello6: import('../components/hello6')
|
2017-05-15 04:44:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 13:19:34 +00:00
|
|
|
if (props.showMore) {
|
|
|
|
components.Hello7 = import('../components/hello7')
|
|
|
|
}
|
|
|
|
|
|
|
|
return components
|
|
|
|
},
|
|
|
|
render: (props, { Hello6, Hello7 }) => (
|
|
|
|
<div style={{padding: 10, border: '1px solid #888'}}>
|
|
|
|
<Hello6 />
|
|
|
|
{Hello7 ? <Hello7 /> : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
export default class Index extends React.Component {
|
|
|
|
static getInitialProps ({ query }) {
|
|
|
|
return { showMore: Boolean(query.showMore) }
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleShowMore () {
|
|
|
|
const { showMore } = this.props
|
|
|
|
if (showMore) {
|
|
|
|
Router.push('/')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Router.push('/?showMore=1')
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { showMore } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Header />
|
|
|
|
<DynamicComponent />
|
|
|
|
<DynamicComponentWithCustomLoading />
|
|
|
|
<DynamicComponentWithNoSSR />
|
|
|
|
<DynamicComponentWithAsyncReactor />
|
|
|
|
<DynamicBundle showMore={showMore} />
|
|
|
|
<button onClick={() => this.toggleShowMore()}>Toggle Show More</button>
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Since DynamicComponent5 does not render in the client,
|
|
|
|
it won't get downloaded.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
{ React.noSuchField === true ? <DynamicComponent5 /> : null }
|
|
|
|
|
|
|
|
<p>HOME PAGE is here!</p>
|
|
|
|
<Counter />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|