Last active
October 6, 2019 09:07
-
-
Save HarisSpahija/5dbd7fbe94dd64952c7665bfef3377fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, { Fragment } from "react"; | |
| import axios from "axios"; | |
| import "./App.css"; | |
| export default class App extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| pages: [] | |
| }; | |
| } | |
| getAllPages = async () => { | |
| let res = await axios.get( | |
| `http://localhost:8000/?rest_route=/wp/v2/pages` | |
| ); | |
| let { data } = await res; | |
| this.setState({ pages: data }); | |
| }; | |
| componentDidMount = async () => { | |
| await this.getAllPages(); | |
| }; | |
| render() { | |
| const { pages } = this.state; | |
| return ( | |
| <Fragment> | |
| {pages.map((page, index) => { | |
| return <h1>{page.slug}</h1>; | |
| })} | |
| </Fragment> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment