Skip to content

Instantly share code, notes, and snippets.

@emilpriver
Created January 20, 2020 12:43
Show Gist options
  • Save emilpriver/0057b83980e8f0ae5a87d99859a7d66a to your computer and use it in GitHub Desktop.
Save emilpriver/0057b83980e8f0ae5a87d99859a7d66a to your computer and use it in GitHub Desktop.
Write getStaticProps function
## Example 1:
export async function getStaticProps() {
const data = await axios
.get("https://api.priver.dev/wp-json/wp/v2/works?filter=[orderby]=date")
.then(d => d.data);
console.log(data);
return { props: { projects: data } };
}
class Home extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
## Example 2:
Home.getStaticProps = async () => {
const data = await axios
.get("https://api.priver.dev/wp-json/wp/v2/works?filter=[orderby]=date")
.then(d => d.data);
console.log(data);
return { props: { projects: data } };
};
## Example 3
class Home extends React.Component {
static async getStaticProps() {
const projects = await axios
.get("https://api.priver.dev/wp-json/wp/v2/works?filter=[orderby]=date")
.then(d => d.data);
return { projects };
}
constructor(props) {
super(props);
this.state = {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment