react-postcode-lookup

A component library for postcode lookup via First Class Postcode API

Usage no npm install needed!

<script type="module">
  import reactPostcodeLookup from 'https://cdn.skypack.dev/react-postcode-lookup';
</script>

README

Postcode Lookup

An extensible component enabling UK postcode lookup, via the First Class Postcode API

NPM JavaScript Style Guide Build Status codecov semantic-release Conventional Commits

Example Address Form

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