Created
October 6, 2018 13:46
-
-
Save manoelneto/6220c699a8a80eff5f292081eda1d06c to your computer and use it in GitHub Desktop.
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
const PostList = ({posts}) => ( | |
posts.map(post => <Post post={post} />) | |
) | |
class PostPage extends Component { | |
state = { | |
posts: [], | |
category: "" | |
} | |
componentDidMount() { | |
fetchPost().then(posts => this.setState({posts})) | |
} | |
render() { | |
const { | |
category | |
} = this.state; | |
const posts = this.state.posts.filter(post => post.category === category) | |
return <> | |
<input | |
type="text" | |
onChange={e => this.setState({category: e.target.value})} | |
value={category} | |
/> | |
<PostList posts={this.state.posts} /> | |
</> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment