@@ -16,6 +16,8 @@ import { BrowserRouter as Router, Route } from "react-router-dom";
1616// Import EmailJs for initiation
1717import emailjs from "@emailjs/browser" ;
1818import { EMAILJS_USER } from "./config/keys" ;
19+ import { WP_REST_GET_POSTS_URL } from "./config/keys" ;
20+ import axios from "axios" ;
1921
2022// Import main site components
2123import NavBar from "./components/NavBar" ;
@@ -36,8 +38,21 @@ import Footer from "./components/Footer";
3638 * @returns primary router component of the App
3739 */
3840class App extends Component {
41+ state = { posts : [ ] , selectedPost : "" } ;
42+
3943 componentDidMount ( ) {
40- console . log ( "app props" , this . props . posts ) ;
44+ let blogPosts = [ ] ;
45+ axios . get ( WP_REST_GET_POSTS_URL ) . then ( ( response ) => {
46+ blogPosts = response . data ;
47+ for ( let blog of blogPosts ) {
48+ blog . excerpt . rendered = blog . excerpt . rendered
49+ . replace ( / ( ^ " | " $ ) / g, "" )
50+ . replace ( "[" , "" )
51+ . replace ( "]" , "" ) ;
52+ }
53+ this . setState ( { posts : blogPosts } ) ;
54+ console . log ( "state" , this . state ) ;
55+ } ) ;
4156 }
4257
4358 render ( ) {
@@ -48,15 +63,15 @@ class App extends Component {
4863 < ScrollToTop />
4964 < NavBar />
5065 < Route exact path = "/" >
51- < LandingPage posts = { this . props . posts } />
66+ < LandingPage posts = { this . state . posts } />
5267 </ Route >
5368 < Route exact path = "/about" >
5469 < AboutPage />
5570 </ Route >
5671 < Route exact path = "/posts" >
57- < PostsPage posts = { this . props . posts } />
72+ < PostsPage posts = { this . state . posts } />
5873 </ Route >
59- < Route exact path = "/post" posts = { this . props . posts } >
74+ < Route exact path = "/post" posts = { this . state . posts } >
6075 < PostPage />
6176 </ Route >
6277 < Route exact path = "/contact" >
0 commit comments