Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Last active January 9, 2017 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThisIsMissEm/5e8b4409c9b23ecdd04049923e280195 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/5e8b4409c9b23ecdd04049923e280195 to your computer and use it in GitHub Desktop.
// 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")
);
@gr2m
Copy link

gr2m commented Jan 9, 2017

not directly related to your challenges with Hoodie right now, but would recommend PouchDB: require('pouchdb-browser') over PouchDB: require('pouchdb')

@gr2m
Copy link

gr2m commented Jan 9, 2017

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