Created
October 6, 2018 14:09
-
-
Save manoelneto/5b3d1d8452516c4fe11aa378ee46ce74 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
import memoize from "memoize-one" | |
const PostList = ({posts}) => ( | |
posts.map(post => <Post post={post} />) | |
) | |
class PostPage extends Component { | |
state = { | |
posts: [], | |
category: "" | |
} | |
componentDidMount() { | |
fetchPost().then(posts => this.setState({posts})) | |
} | |
filterPosts = memoize( | |
(posts, category) => posts.filter(post => post.category === category) | |
) | |
render() { | |
const { | |
category | |
} = this.state; | |
const posts = this.filterPosts(this.state.posts, 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