Skip to content

Instantly share code, notes, and snippets.

@modos
Created July 14, 2023 18:02
Show Gist options
  • Save modos/b335b0f81725856e6e069d49796e02e3 to your computer and use it in GitHub Desktop.
Save modos/b335b0f81725856e6e069d49796e02e3 to your computer and use it in GitHub Desktop.
Input Mask
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