Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@qc/react-geocoder

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qc/react-geocoder

Makes geocoding in React easy.

latest
Source
npmnpm
Version
0.0.0-alpha
Version published
Maintainers
1
Created
Source

@qc/react-geocoder

Makes geocoding in React easy.

Installation

npm install --save @qc/react-geocoder

or

yarn add @qc/react-geocoder

Usage

The Geocoder component uses the children property as a render prop. That is, it expects a single nested child that is a function. This function will be passed an object with several properties.

import React from 'react';

import Geocoder from '@qc/react-geocoder';

class Example(props) {

  state = {
    address: '',
  };

  handleAddressChange = evt => {
    this.setState({
      address: evt.target.value,
    })
  }

  render() {
    const { address } = this.state;
    return (
      <div>
        <label>
          Address
          <input type="text" onChange={this.handleAddressChange} value={address} />
        </label>
        <Geocoder apiKey="YOUR_API_KEY" address={address}>
          {
            ({ error, loading, results }) => {
              if (loading) {
                return <p>Loading...</p>;
              }
              if (error) {
                return <p>Error: {error.message}</p>;
              }
              if (results) {
                if (results.length === 0) {
                  return <p>No results match "{address}".</p>
                }
                return (
                  <ul>
                    {results.map(result => <li>{result.formatted_address}</li>)}
                  </ul>
                );
              }
            }
          }
        </Geocoder>
      </div>
    );
  }
}

Other Packages from QC

Maintainers

License

ISC

Keywords

geocode

FAQs

Package last updated on 15 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts