Created
January 20, 2020 12:43
-
-
Save emilpriver/0057b83980e8f0ae5a87d99859a7d66a to your computer and use it in GitHub Desktop.
Write getStaticProps function
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
## 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