Last active
November 13, 2017 19:23
-
-
Save richsalvucci/cb14d6093f3c17efb6c7ca066d9eeaf4 to your computer and use it in GitHub Desktop.
React with WordPress Test
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
import React, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
movies: [] | |
} | |
} | |
componentDidMount() { | |
let dataURL = "http://localhost:3000/wp-json/wp/v2/movie?_embed"; | |
fetch(dataURL) | |
.then(res => res.json()) | |
.then(res => ( | |
console.log(res) | |
) | |
.then(res => { | |
this.setState({ | |
movies: res | |
}); | |
}); | |
} | |
render() { | |
let movies = this.state.movies.map((movie, index) => { | |
return (<div key={index}> | |
<p><strong>Title:</strong>{movie.title.rendered}</p> | |
<p><strong>Release Year:</strong> {movie.release_year}</p> | |
<p><strong>Rating:</strong>{movie.rating}</p> | |
<div><strong>Description:</strong><div | |
dangerouslySetInnerHTML={ {__html: movie.description} } / ></div> | |
</div>); | |
}); | |
return ( | |
<div className="App"> | |
<h2>Movies</h2> | |
{movies} | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment