npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@address-checker/react-native-component

v0.1.0

Published

A react native Expo component that can be used to verify and check addresses

Downloads

7

Readme

Address Checker React Native Component

A React native Expo component that can be used to verify and check addresses.

Preview

To run an example project with this component, use:

yarn run example

Installation

npm install @address-checker/react-native-component

Initialization

To use the address checker component, you need to wrap your application with the AddressCheckerProvider component and pass the apiKey prop. Furthermore, you can also adjust the instance of address checker and styles:

type AddressCheckerContextType = {
  apiKey: string; // The API key to use for the address checker
  useL1L2FromServer?: boolean; // Whether to use the L1 and L2 fields from the server response or use the cached version (false by default)
  theme?: ThemeProps; // The theme to use for the address checker in a ThemeProps type
};

// The theme to use for the address checker
// Higher values indicate darker hues
type ThemeProps = {
  // Generally better to be use a dark color for the primary color (to indicate action or highlight)
  primary: {
    900: string;
    600: string;
  };
  // Generally better to be use a light color for the secondary color (to indicate background or light action)
  secondary: {
    500: string;
    400: string;
    200: string;
  };
};

// Example App init
const theme = {
  primary: {
    900: '#000000',
    600: '#14213D',
  },
  secondary: {
    500: '#E5E5E5',
    400: '#E8E8E8',
    200: '#FFFFFF',
  },
};

const App = () => {
  return (
    <AddressCheckerProvider value={{ apiKey: 'vera_...', theme, useL1L2FromServer: true }}>
      <RestOfTheApplication />
    </AddressCheckerProvider>
  );
}

Usage - Autocomplete

The Autocomplete component can be used to provide an autocomplete search bar for addresses.

  • It uses debouncing of 500ms (by default, or other ms amount by providing a custom debounceTime as a prop) to prevent too many requests to the server.
  • The onAddressSelected prop is called with an address (string) when an option is selected.
  • The onNoResultsFound prop is called when no results are found or there is another error with the error as string.
  • The styleContainer prop can be used to style the container of the autocomplete component.
  • The selectedCountry prop is used to determine the country to search for addresses in. (only fully-supported counties are allowed)
import {
  AddressCheckerProvider,
  Autocomplete,
  CountryDropdown,
} from '@address-checker/react-native-component';
import { FullySupportedCountryCode, supportedCountries } from '@address-checker/api';

const App = () => {
  const [country, setCountry] = useState('default');

  return (
    <AddressCheckerProvider value={{ apiKey: '<YOUR-KEY>' }}>
      <View>
        <CountryDropdown
          selectedCountry={country}
          setSelectedCountry={setCountry}
        />
        {
          supportedCountries.includes(country as FullySupportedCountryCode)
            ? (<Autocomplete
              styleContainer={{ width: '100%', marginTop: 20 }}
              selectedCountry={selectedCountry}
              onAddressSelected={(address: string) => console.log('Address selected: ' + address)}
              onNoResultsFound={(error: string) => console.log(error)}
            />)
            : <Text>Country not supported</Text>
        }
      </View>
    </AddressCheckerProvider>
  );
}

export default App;

Usage - Required Fields Form

The RequiredFieldsForm component can be used to provide a form for users to fill in their address based on the country selected.

  • The selectedCountry prop is used to determine the country to search for addresses in. (only fully-supported counties allow for search, partially supported countries return form schemas and format validation props, but cannot determine addresses)
  • The onValidAddressSubmitted prop is called with an address (string) when the form is filled out correctly and an address is found.
  • The onInvalidAddressSubmitted prop is called when the form is filled out incorrectly (no address is found).
  • The styleContainer prop can be used to style the container of the form.
import {
  AddressCheckerProvider,
  CountryDropdown,
  RequiredFieldsForm,
} from '@address-checker/react-native-component';

const App = () => {
  const [country, setCountry] = useState('default');

  return (
    <AddressCheckerProvider value={{apiKey: '<YOUR-KEY>'}}>
      <View>
        <CountryDropdown
          selectedCountry={country}
          setSelectedCountry={setCountry}
        />
        <RequiredFieldsForm
          styleContainer={{width: '100%', marginTop: 20}}
          selectedCountry={selectedCountry}
          onValidAddressSubmitted={(address: string) => console.log('Address found: ' + address)}
          onInvalidAddressSubmitted={(_: { [key: string]: string }, error: string) => console.log(error)}
        />
      </View>
    </AddressCheckerProvider>
  );
}

export default App;

Advanced Usage

For a more concrete example of how to use the address checker component, please refer to the example project under the example/ directory.

Acknowledgements

Made with create-react-native-library