Skip to content

Instantly share code, notes, and snippets.

@mihir-kanzariya
Created November 14, 2019 09:15
Show Gist options
  • Save mihir-kanzariya/f11377a28badb4471cfc033572d7c862 to your computer and use it in GitHub Desktop.
Save mihir-kanzariya/f11377a28badb4471cfc033572d7c862 to your computer and use it in GitHub Desktop.
// Simple Search component
function App() {
const [state, setState] = React.useState([])
const arr = ["john wick", "Waldo", "Johnson", "Edwardo", "marry mick"]
const handleChange = (e) => {
const value = e.target.value
const newArr = arr.filter(ele => RegExp(value, "gi").exec(ele))
setState(newArr)
}
return (
<div className="App">
<input onChange={handleChange} />
{state.map(ele => (<div>{ele}</div>))}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment