Created
July 14, 2023 18:02
-
-
Save modos/b335b0f81725856e6e069d49796e02e3 to your computer and use it in GitHub Desktop.
Input Mask
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
import React, {useState} from 'react'; | |
import Input from "./Input"; | |
const cities = require("./cities.json"); | |
function App() { | |
const [hint, setHint] = useState(""); | |
const handleChange = (e) => { | |
for (const city of cities) { | |
if (city.startsWith(e.target.value) && e.target.value.length) { | |
return city; | |
} | |
} | |
return ""; | |
} | |
return <div> | |
<Input handleChange={(e) => setHint(handleChange(e))} hint={hint}/> | |
</div> | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment