filter based on input typing react

Solutions on MaxInterview for filter based on input typing react by the best coders in the world

showing results for - "filter based on input typing react"
Ousmane
23 Nov 2020
1const List = ({ data }) => {
2  const [value, setValue] = useState('')
3
4  return (
5    <div>
6      <input 
7        type="text"
8        value={value} 
9        onChange={e => setValue(e.target.value)} 
10      />
11
12      {data
13        .filter(item => {
14          if (!value) return true
15          if (item.title.includes(value) || item.text.includes(value)) {
16            return true
17          }
18        })
19        .map(item => (
20          <div>
21            <h1>{item.title}</h1>
22            <p>{item.text}</p>
23          </div>
24        ))
25      }
26    </div>
27  )
28}
29