Guest User

Untitled

a guest
Mar 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import store from '../../store'
  2. import {connect} from "react-redux";
  3. import {bindActionCreators} from "redux";
  4.  
  5. /* Your store has lots of different properties, but this particular component only needs to use `loggedin`.
  6. What we will do is copy the value from store's props to a local-only state value. */
  7.  
  8. constructor() {
  9. super();
  10. this.state = {
  11. // Use store version of property if available, otherwise set to a default (false here)
  12. loggedin: (typeof store.getState().authentication.loggedin !== 'boolean') ? false : store.getState().authentication.loggedin
  13. }
  14. store.subscribe(() => {
  15. // This is a listener for changes in any and all store properties.
  16. this.setState({
  17. loggedin: store.getState().authentication.loggedin,
  18. })
  19. })
  20. }
  21.  
  22. // your render here....
  23.  
  24. // After component definition:
  25. const mapStateToProps = state => ({})
  26.  
  27. const mapDispatchToProps = dispatch => bindActionCreators({}, dispatch)
  28.  
  29. export default connect(
  30. mapStateToProps,
  31. mapDispatchToProps
  32. )(App)
Add Comment
Please, Sign In to add comment