mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
ebf0c47c25
* Upgrade standard.js # Conflicts: # yarn.lock * Upgrade babel-eslint
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import React from 'react'
|
|
import Link from 'next/link'
|
|
import withRedux from 'next-redux-wrapper'
|
|
import initStore from '../redux'
|
|
import CharacterInfo from '../components/CharacterInfo'
|
|
import { rootEpic } from '../redux/epics'
|
|
import * as actions from '../redux/actions'
|
|
import { of } from 'rxjs/observable/of'
|
|
|
|
class Counter extends React.Component {
|
|
static async getInitialProps ({ store, isServer }) {
|
|
const resultAction = await rootEpic(
|
|
of(actions.fetchCharacter(isServer)),
|
|
store
|
|
).toPromise() // we need to convert Observable to Promise
|
|
store.dispatch(resultAction)
|
|
|
|
return { isServer }
|
|
}
|
|
|
|
componentDidMount () {
|
|
this.props.startFetchingCharacters()
|
|
}
|
|
|
|
componentWillUnmount () {
|
|
this.props.stopFetchingCharacters()
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<div>
|
|
<h1>Index Page</h1>
|
|
<CharacterInfo />
|
|
<br />
|
|
<nav>
|
|
<Link href='/other'><a>Navigate to "/other"</a></Link>
|
|
</nav>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default withRedux(
|
|
initStore,
|
|
null,
|
|
{
|
|
startFetchingCharacters: actions.startFetchingCharacters,
|
|
stopFetchingCharacters: actions.stopFetchingCharacters
|
|
}
|
|
)(Counter)
|