2017-06-16 13:19:34 +00:00
|
|
|
import React from 'react'
|
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import Router from 'next/router'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
|
|
|
const HelloBundle = dynamic({
|
|
|
|
modules: (props) => {
|
|
|
|
const components = {
|
|
|
|
HelloContext: import('../../components/hello-context'),
|
2018-07-24 09:24:40 +00:00
|
|
|
Hello1: import('../../components/hello1'),
|
|
|
|
Hello2: import('../../components/hello2')
|
2017-06-16 13:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return components
|
|
|
|
},
|
|
|
|
render: (props, { HelloContext, Hello1, Hello2 }) => (
|
|
|
|
<div>
|
|
|
|
<h1>{props.title}</h1>
|
|
|
|
<HelloContext />
|
|
|
|
<Hello1 />
|
2018-07-24 09:24:40 +00:00
|
|
|
{props.showMore ? <Hello2 /> : null}
|
2017-06-16 13:19:34 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
export default class Bundle extends React.Component {
|
|
|
|
static childContextTypes = {
|
|
|
|
data: PropTypes.object
|
|
|
|
}
|
|
|
|
|
2018-08-07 03:53:06 +00:00
|
|
|
static getInitialProps ({ query }) {
|
|
|
|
return { showMore: Boolean(query.showMore) }
|
|
|
|
}
|
|
|
|
|
2017-06-16 13:19:34 +00:00
|
|
|
getChildContext () {
|
|
|
|
return {
|
|
|
|
data: { title: 'ZEIT Rocks' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleShowMore () {
|
|
|
|
if (this.props.showMore) {
|
|
|
|
Router.push('/dynamic/bundle')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Router.push('/dynamic/bundle?showMore=1')
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { showMore } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<HelloBundle showMore={showMore} title="Dynamic Bundle"/>
|
|
|
|
<button
|
|
|
|
id="toggle-show-more"
|
|
|
|
onClick={() => this.toggleShowMore()}
|
|
|
|
>
|
|
|
|
Toggle Show More
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|