Skip to content

Instantly share code, notes, and snippets.

@HarisSpahija
Last active October 6, 2019 09:07
Show Gist options
  • Select an option

  • Save HarisSpahija/5dbd7fbe94dd64952c7665bfef3377fd to your computer and use it in GitHub Desktop.

Select an option

Save HarisSpahija/5dbd7fbe94dd64952c7665bfef3377fd to your computer and use it in GitHub Desktop.
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