Skip to content

Instantly share code, notes, and snippets.

@natafaye
Created September 15, 2021 00:46
Show Gist options
  • Save natafaye/b49ad38f1113daa7399321b26202fa40 to your computer and use it in GitHub Desktop.
Save natafaye/b49ad38f1113daa7399321b26202fa40 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import PostList from './components/PostList'
export default class App extends Component {
render() {
return (
<div>
This text is in App.js
<PostList/>
</div>
)
}
}
import React, { Component } from 'react'
export default class Post extends Component {
render() {
const post = {
text: "This is a hard coded post",
author: "Natalie"
}
return (
<div>
<h2>{ post.author }</h2>
<p>{ post.text }</p>
<button>Comment</button>
</div>
)
}
}
import React, { Component } from 'react'
import Post from './Post'
export default class PostList extends Component {
render() {
const posts = [
{
text: "1 post",
author: "Natalie"
},
{
text: "2 post",
author: "Linda"
},
{
text: "3 post",
author: "Jennifer"
},
{
text: "4 post",
author: "Natalie"
},
]
// We're making a post for each post we have in the list, but we're not actually telling our Post component
// which post it should be displaying. We'll need props for that!
return (
<div>
{ posts.map(post => <Post/> ) }
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment