Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react';
- class Posty extends Component{
- constructor(props){
- super(props);
- this.state = {
- postsList: [],
- };
- this.getPostsFromAPI();
- }
- getPostsFromAPI() {
- fetch('https://jsonplaceholder.typicode.com/posts')
- .then((response) => {
- return response.json();
- })
- .then((myJson) => {
- this.setState({
- postsList: myJson,
- });
- });
- }
- render() {
- return <div>{this.state.postsList.map(item => <PostItem item = {item}/>)}</div>;
- }
- }
- class PostItem extends Component{
- constructor(output){
- super(output);
- this.output = output;
- }
- render(){
- return(<div>
- {console.log(this.output)}
- {this.output}
- </div>);
- }
- }
- export default Posty;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement