Last active
January 9, 2017 20:06
-
-
Save ThisIsMissEm/5e8b4409c9b23ecdd04049923e280195 to your computer and use it in GitHub Desktop.
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
// views/Documents.js | |
function Documents(props) { | |
return ( | |
<ul> | |
{props.documents.map((doc) => <li>{doc.id} - {doc.title}</li>)} | |
</ul> | |
) | |
} | |
Documents.propTypes = { | |
documents: PropTypes.arrayOf(PropTypes.shape({ | |
id: PropTypes.string.isRequired, | |
title: PropTypes.string.isRequired | |
})).isRequired | |
}; | |
// containers/Documents.js | |
// This is the file that is used by the router | |
class DocumentsContainer extends Component { | |
static contextTypes = { | |
hoodie: PropTypes.object.isRequired | |
} | |
componentWillMount() { | |
const { hoodie } = this.context; | |
const store = hoodie.store("documents"); | |
store.on("change", this.fetchDocuments.bind(this, store)); | |
this.fetchDocuments(store); | |
} | |
fetchDocuments(store) { | |
store.findAll().then((documents) => { | |
this.setState({ | |
documents: documents | |
}) | |
}) | |
} | |
render() { | |
return <Documents documents={this.state.documents} /> | |
} | |
} | |
// index.js | |
var HoodieProvider = // https://gist.github.com/ThisIsMissEm/2a1babb16cbd8cd1123576e2c978b20a | |
var Hoodie = require('@hoodie/client') | |
var hoodie = new Hoodie({ | |
url: 'https://myhoodieapp.com', | |
PouchDB: require('pouchdb') | |
}) | |
ReactDOM.render( | |
( | |
<HoodieProvider hoodie={hoodie}> | |
<DocumentsContainer /> | |
</HoodieProvider> | |
), document.getElementById("root") | |
); |
You need to wait for the hoodie.ready
promise to finish before you can use the hoodie.store
or the hoodie.account
APIs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not directly related to your challenges with Hoodie right now, but would recommend
PouchDB: require('pouchdb-browser')
overPouchDB: require('pouchdb')