Google Search functionality using react
Jun 25, 2021
Its a basic code which gives an idea about how to do search functionality like a google
const { useState,useEffect }=Reactconst App=()=>{const data1=[{id:1,name:'prafull'},{id:2,name:'revan'},{id:3,name:'xyz'},{id:4,name:'node'},{id:5,name:'react'},{id:6,name:'science'},{id:7,name:'data'},{id:8,name:'angular'},{id:9,name:'figma'}]const [data,setData]=useState(data1)const [name,setName]=useState('')const [list,setList]=useState([])const handleChange=(e)=>{const result=e.target.valueconst d=data.filter((ele)=>{if(ele.name.includes(result)){return ele}})setName(result)setList(d)}return (<div><h1>Search functionality keypress</h1><label>enter text to search</label><input type="text" value={name} onChange={handleChange}/><ul>{ list.length !==0 ?list.map((ele)=>{return <li key={ele.id}>{ele.name}</li>}) :data.map((ele)=>{return <li key={ele.id}>{ele.name}</li>})}</ul></div>)}ReactDOM.render(<App/>,rootHandle)