Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import React from 'react';
  2. import {bindActionCreators} from "redux";
  3. import {connect} from 'react-redux';
  4. import * as actions from '../actions';
  5. import Events from '../components/Events';
  6. import AddEvent from '../components/AddEvent';
  7.  
  8. function mapStateToProps(state){
  9. // my store is structured like this: {routing: {}, state{ events: {}}}
  10. const {events} = state.state;
  11. return {
  12. events: events
  13. }
  14. }
  15.  
  16. // Implementing this after mapStateToProps is working
  17. function mapDispatchToProps(dispatch){
  18. return {
  19. dispatchAddEvent: bindActionCreators(actions.fetchEvents, dispatch)
  20. }
  21. }
  22.  
  23.  
  24. class EventsContainer extends React.Component {
  25. constructor(props) {
  26. super(props);
  27. }
  28.  
  29. componentDidMount() {
  30. const {store} = this.context;
  31. // need to actually fetch events for them to load
  32. store.dispatch(actions.fetchEvents());
  33. }
  34.  
  35. addEvent(eventName) {
  36. const {store} = this.context;
  37. store.dispatch(actions.addEvent(eventName));
  38. }
  39.  
  40. render() {
  41. return(
  42. <div>
  43. <Events events={this.props.events} />
  44. <AddEvent addEvent={this.addEvent.bind(this)}/>
  45. </div>);
  46. }
  47. }
  48.  
  49. EventsContainer.contextTypes = {
  50. store: React.PropTypes.object
  51. };
  52.  
  53. export default connect(mapStateToProps)(EventsContainer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement