Skip to content

Commit

Permalink
Merge pull request #18 from lob/readme
Browse files Browse the repository at this point in the history
Updates sample code in readme and updates to latest autocomplete
  • Loading branch information
mmrtnz authored May 13, 2022
2 parents 7f2277b + fe3a361 commit 6f9cf7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,36 @@ const App = () => {

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

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

const AddressFormDemo = () => {
const [address, setAddress] = useState({})

const handleSelect = (selected) => {
setSelectedResult(selected)
const handleFieldChange = (payload) => {
console.log(`${payload.event.target.id} Field Change`, payload)
setAddress(payload.address)
}

const handleSubmit = () =>
// Set this to handle an actual button click
console.log(selectedResult)
const handleSelect = (selection) => {
console.log('Address Selection', selection)
setAddress(selection.value)
}

const handleSubmit = () => {
verify(API_KEY, address).then((verificationResult) => {
console.log('Verification Results', verificationResult)
})
}

return (
<div className="demoContainer">
<h2>Address Form</h2>
<AddressForm
apiKey={apiKey}
apiKey={API_KEY}
onSelection={handleSelect}
onFieldChange={handleFieldChange}
/>
<button
onClick={handleSubmit}
Expand Down
12 changes: 6 additions & 6 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f9cf7e

Please sign in to comment.