use-cep-hook
A simple React Hook to fetch info from the https://viacep.com.br
Last updated 4 months ago by mateusandrade .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install use-cep-hook 
SYNC missed versions from official npm registry.

use-cep-hook :earth_americas: npm

This is a simple React Hooks that let you search for a brazillian postal-code on: https://viacep.com.br.

Installation

Just run a yarn add use-cep-hook or npm i --save use-cep-hook

How to use

Simply import use-cep-hook on your component, then call this on that way:

import useViaCep from "use-cep-hook";

const Foo = () => {
  const [postalCode, setPostalCode] = useState("");

  const [loading, cep, error] = useViaCep(postalCode);

  return (
    <div className="field">
      <label>CEP:</label>
      <input onChange={e => setPostalCode(e.target.value)} value={postalCode} />
    </div>
  );
};

Every time that the argument passed to the hooks get a length of 8, this will trigger a call to the API, changing the loading param to true.

TODO:

  • [ ] Port to TS
  • [ ] Apply some cool CSS to example
  • [ ] Write TESTS!
  • [ ] Deploy example to surge.sh!
  • [ ] Configure Github Actions

Current Tags

  • 1.0.3                                ...           latest (4 months ago)

4 Versions

  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |