Skip to content

Instantly share code, notes, and snippets.

@manoelneto
Created October 6, 2018 13:46
Show Gist options
  • Save manoelneto/6220c699a8a80eff5f292081eda1d06c to your computer and use it in GitHub Desktop.
Save manoelneto/6220c699a8a80eff5f292081eda1d06c to your computer and use it in GitHub Desktop.
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