Skip to content

Instantly share code, notes, and snippets.

@tkh44
Forked from VictorCoding/index.js
Last active September 17, 2017 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkh44/1df01ea110ec92925e424aff404a814b to your computer and use it in GitHub Desktop.
Save tkh44/1df01ea110ec92925e424aff404a814b to your computer and use it in GitHub Desktop.
working with search/filtering items
import React from 'react'
import { Div } from 'glamorous'
const filterPosts = (posts, term) => posts.filter(item => item.includes(term))
function List({ items }) {
return <ul>{items.map((p, i) => <li key={i}>{p}</li>)}</ul>
}
class Index extends React.Component {
state = {
posts: ['first', 'second', 'third'],
search: ''
}
render() {
return (
<Div
css={{
display: 'flex',
flexDirection: 'column'
}}
>
<Div
css={{
fontSize: '2.2em',
display: 'flex',
justifyContent: 'center',
height: '10%',
fontWeight: '200'
}}
>
VicAdventures
</Div>
<Div
css={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center'
}}
>
<input
onChange={({ target: { value } }) =>
this.setState({ search: value })}
/>
<List items={filterPosts(this.state.posts, this.state.search)} />
</Div>
</Div>
)
}
}
export default Index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment