Created
April 27, 2021 08:08
-
-
Save keichan34/ea2c4069fc82edd8d8f2aff13fa80115 to your computer and use it in GitHub Desktop.
normalize-japanese-addresses のサンプル React App
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, { useCallback, useState } from 'react' | |
import { normalize, NormalizeResult } from '@geolonia/normalize-japanese-addresses' | |
interface Result { | |
input: string | |
normalized: NormalizeResult | |
} | |
const App: React.FC = () => { | |
const [ result, setResult ] = useState<Result | undefined>(undefined) | |
const onSubmit = useCallback(async (ev: React.FormEvent) => { | |
ev.preventDefault() | |
const inputText = (ev.currentTarget as any)['input']?.value | |
if (!inputText) return | |
const normalized = await normalize(inputText) | |
setResult({ | |
input: inputText, | |
normalized, | |
}) | |
}, []) | |
return ( | |
<div className="container"> | |
<form onSubmit={onSubmit} className="mb-3 mt-5"> | |
<div className="mb-3"> | |
<label htmlFor="input" className="form-label">住所</label> | |
<input type="text" name="input" className="form-control" /> | |
</div> | |
<button type="submit" className="btn btn-primary">正規化</button> | |
</form> | |
{ typeof result !== 'undefined' && <div> | |
<p>{result.input}</p> | |
<pre>{JSON.stringify(result.normalized, undefined, 2)}</pre> | |
</div> } | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment