Skip to content

Instantly share code, notes, and snippets.

@manoelneto
Created October 6, 2018 13:46
Show Gist options
  • Select an option

  • Save manoelneto/6220c699a8a80eff5f292081eda1d06c to your computer and use it in GitHub Desktop.

Select an option

Save manoelneto/6220c699a8a80eff5f292081eda1d06c to your computer and use it in GitHub Desktop.

Revisions

  1. manoelneto created this gist Oct 6, 2018.
    33 changes: 33 additions & 0 deletions posts.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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} />
    </>
    }
    }