2017-08-27 20:13:35 +00:00
|
|
|
import React from 'react'
|
2018-12-17 16:34:32 +00:00
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { namespaceConfig } from 'fast-redux'
|
2017-08-27 20:13:35 +00:00
|
|
|
import Link from 'next/link'
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const DEFAULT_STATE = { build: 1 }
|
2017-08-27 20:13:35 +00:00
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
const { actionCreator, getState: getHomepageState } = namespaceConfig(
|
|
|
|
'homepage',
|
|
|
|
DEFAULT_STATE
|
|
|
|
)
|
2017-08-27 20:13:35 +00:00
|
|
|
|
|
|
|
const bumpBuild = actionCreator(function bumpBuild (state, increment) {
|
2018-12-17 16:34:32 +00:00
|
|
|
return { ...state, build: state.build + increment }
|
2017-08-27 20:13:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const Homepage = ({ build, bumpBuild }) => (
|
|
|
|
<div>
|
|
|
|
<h1>Homepage</h1>
|
|
|
|
<h3>Current build: {build}</h3>
|
2018-12-17 16:34:32 +00:00
|
|
|
<p>
|
|
|
|
<button onClick={e => bumpBuild(1)}>Bump build!</button>
|
|
|
|
</p>
|
|
|
|
<Link href='/about'>
|
|
|
|
<a>About Us</a>
|
|
|
|
</Link>
|
2017-08-27 20:13:35 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return getHomepageState(state)
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return bindActionCreators({ bumpBuild }, dispatch)
|
|
|
|
}
|
|
|
|
|
2018-12-17 16:34:32 +00:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Homepage)
|