Skip to content

Instantly share code, notes, and snippets.

@keichan34
Created April 27, 2021 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichan34/ea2c4069fc82edd8d8f2aff13fa80115 to your computer and use it in GitHub Desktop.
Save keichan34/ea2c4069fc82edd8d8f2aff13fa80115 to your computer and use it in GitHub Desktop.
normalize-japanese-addresses のサンプル React App
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