react-postcode-lookup
v2.0.0
Published
A component library for postcode lookup via First Class Postcode API
Downloads
6
Maintainers
Readme
Postcode Lookup
An extensible component enabling UK postcode lookup, via the First Class Postcode API
Install
npm install --save react-postcode-lookup
Usage
If you don't already have an API key, head over to https://firstclasspostcodes.com to sign up for free. This includes a limit of 2000 requests per month, which is more than enough for development purposes.
The most basic usage of the library is to include the component on your page. This will render a very "basic" form, which whilst working, is pretty much useless. See below.
import React, { Component } from 'react'
import PostcodeLookup from 'react-postcode-lookup'
class Example extends Component {
render () {
const { apiKey } = this.props;
return (
<PostcodeLookup onSelect={addr => console.log(addr)} apiKey={apiKey} />
);
}
}
The following props can be used to customise the appearance of the form and when coupled with React portals, can be tailored to accommodate any checkout form.
Fetch
You may need to use a library similar to whatwg-fetch to polyfill window.fetch
. This library does not polyfill it and assumes that fetch is present and working correctly.
License
MIT © First Class Postcodes