Created
February 27, 2019 14:03
-
-
Save koyta/6eb99828dec608fd3615994fadebdee9 to your computer and use it in GitHub Desktop.
next js redux use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { bindActionCreators } from "redux"; | |
import { startClock, addCount, serverRenderClock } from "../store"; | |
import { connect } from "react-redux"; | |
class Counter extends React.Component { | |
static getInitialProps({ store, isServer }) { | |
store.dispatch(serverRenderClock(isServer)); | |
store.dispatch(addCount()); | |
return { isServer }; | |
} | |
componentDidMount() { | |
this.timer = this.props.startClock(); | |
} | |
componentWillUnmount() { | |
clearInterval(this.timer); | |
} | |
render() { | |
return <div>123</div>; | |
} | |
} | |
const mapDispatchToProps = dispatch => { | |
return { | |
addCount: bindActionCreators(addCount, dispatch), | |
startClock: bindActionCreators(startClock, dispatch) | |
}; | |
}; | |
export default connect( | |
null, | |
mapDispatchToProps | |
)(Counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment