2017-02-21 04:13:05 +00:00
|
|
|
import { connect } from 'refnux'
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
import withRefnux from '../helpers/withRefnux'
|
|
|
|
import getInitialState from '../store/getInitialState'
|
|
|
|
|
|
|
|
// actions
|
|
|
|
import counterIncrement from '../store/counterIncrement'
|
|
|
|
import setTitle from '../store/setTitle'
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const Page1 = connect((state, dispatch) => (
|
|
|
|
<div>
|
|
|
|
<h3>{state.title}</h3>
|
|
|
|
<p>Current state: {JSON.stringify(state, null, 2)}</p>
|
|
|
|
<button onClick={() => dispatch(counterIncrement)}>Increment</button>
|
|
|
|
<Link href='/page2'>
|
|
|
|
<button>go to page 2</button>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
))
|
2017-02-21 04:13:05 +00:00
|
|
|
|
|
|
|
Page1.getInitialProps = async function (context) {
|
2018-12-17 16:34:32 +00:00
|
|
|
const { store } = context
|
2017-02-21 04:13:05 +00:00
|
|
|
// dispatch actions to store to set it up for this page / route
|
|
|
|
store.dispatch(setTitle('Page 1'))
|
|
|
|
return {} // we have a store, we don't need props!
|
|
|
|
}
|
|
|
|
|
2017-02-21 20:52:44 +00:00
|
|
|
export default withRefnux(getInitialState, Page1)
|