Created
November 14, 2019 09:15
-
-
Save mihir-kanzariya/f11377a28badb4471cfc033572d7c862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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