Skip to content

Instantly share code, notes, and snippets.

@bendozy
Created June 22, 2017 01:08
Show Gist options
  • Save bendozy/3d9afbc3457eb15de08283fde2a109cf to your computer and use it in GitHub Desktop.
Save bendozy/3d9afbc3457eb15de08283fde2a109cf to your computer and use it in GitHub Desktop.
import React from 'react';
import Prismic from 'prismic.io';
export default class Pages extends React.Component {
state = {
doc: null,
notFound: false,
}
componentWillReceiveProps(props) {
const api = props.prismicCtx.api;
api.form('everything')
.ref(api.master())
.query(Prismic.Predicates.at("document.type", "page"))
.submit( (err, response) => {
if(err) {
this.setState({ notFound: true });
return;
}
const doc = response.results;
this.setState({ doc });
});
}
render() {
if (this.state.doc) {
return (
<div className="container">
<h1> Pages content ....</h1>
</div>
);
} else if (this.state.notFound) {
return <div> <h2> 404 P Not found </h2></div>;
}
return <h1>Loading Pages</h1>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment