Last active
March 25, 2016 17:07
-
-
Save notakaos/ccc3a709dcd74ca35ef6 to your computer and use it in GitHub Desktop.
Meteor 1.3 + React Simple Memo Step 5-1
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
// imports/ui/containers/AppContainer.js | |
import AppLayout from '../layouts/AppLayout'; | |
import { Memos } from '../../api/memos/memos'; | |
import { createContainer } from 'meteor/react-meteor-data'; | |
const createMemo = content => { | |
Memos.insert({content}); | |
}; | |
export default createContainer(() => { | |
return { | |
memos: Memos.find().fetch(), | |
createMemo, | |
}; | |
}, AppLayout); |
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
// imports/ui/layouts/AppLayout.js | |
import React from 'react'; | |
import Header from '../components/Header'; | |
import MemoList from '../components/MemoList'; | |
export default class AppLayout extends React.Component { | |
constructor(props) { | |
super(props); | |
this.onClick = this.onClick.bind(this); | |
} | |
onClick() { | |
const { memos, createMemo } = this.props; | |
createMemo(`New memo ${memos.length + 1}`); | |
} | |
render() { | |
const { memos } = this.props; | |
return ( | |
<div className="container"> | |
<Header /> | |
<button className="add-button" onClick={this.onClick}>Add</button> | |
<MemoList memos={memos} /> | |
</div> | |
); | |
} | |
} | |
AppLayout.propTypes = { | |
memos: React.PropTypes.array.isRequired, | |
createMemo: React.PropTypes.func.isRequired, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment