Skip to content

Commit fe3a361

Browse files
committed
Updates sample code in readme and updates to latest autocomplete
1 parent 7f2277b commit fe3a361

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

README.md

+19-9
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,36 @@ const App = () => {
5151

5252
```jsx
5353
import React, { useState } from 'react';
54-
import { AddressForm } from '@lob/react-address-autocomplete'
54+
import { AddressForm, verify } from '@lob/react-address-autocomplete'
5555

56-
const AddressFormDemo = ({ apiKey }) => {
57-
const [selectedResult, setSelectedResult] = useState({})
56+
const API_KEY = 'YOUR API KEY HERE'
5857

58+
const AddressFormDemo = () => {
59+
const [address, setAddress] = useState({})
5960

60-
const handleSelect = (selected) => {
61-
setSelectedResult(selected)
61+
const handleFieldChange = (payload) => {
62+
console.log(`${payload.event.target.id} Field Change`, payload)
63+
setAddress(payload.address)
6264
}
6365

64-
const handleSubmit = () =>
65-
// Set this to handle an actual button click
66-
console.log(selectedResult)
66+
const handleSelect = (selection) => {
67+
console.log('Address Selection', selection)
68+
setAddress(selection.value)
69+
}
70+
71+
const handleSubmit = () => {
72+
verify(API_KEY, address).then((verificationResult) => {
73+
console.log('Verification Results', verificationResult)
74+
})
75+
}
6776

6877
return (
6978
<div className="demoContainer">
7079
<h2>Address Form</h2>
7180
<AddressForm
72-
apiKey={apiKey}
81+
apiKey={API_KEY}
7382
onSelection={handleSelect}
83+
onFieldChange={handleFieldChange}
7484
/>
7585
<button
7686
onClick={handleSubmit}

example/package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)