cep-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

cep-hook

CEP do Brasil do WebApi Viacep.com.br

NPM JavaScript Style Guide npm Node.js CI

Install

npm install --save cep-hook

Usage

import React, { useState } from "react";
 
import { useCep } from "cep-hook";
 
const App = () => {
  const initialValue = ""; // Valor inicial ou pode deixar sem valor.
  const [value, setValue, getZip] = useCep(initialValue);
  const [cep, setCep] = useState(null);
 
  const handleClickFindCep = async () => setCep(await getZip());
 
  return (
    <div>
      <div>
        <p>Cep: {cep && cep.cep}</p>
        <p>Logradouro: {cep && cep.logradouro}</p>
        <p>Complemento: {cep && cep.complemento}</p>
        <p>Bairro: {cep && cep.bairro}</p>
        <p>Localidade: {cep && cep.localidade}</p>
        <p>UF: {cep && cep.uf}</p>
        <p>Unidade: {cep && cep.unidade}</p>
        <p>Ibge: {cep && cep.ibge}</p>
        <p>Gia: {cep && cep.gia}</p>
        {cep && cep.status && cep.status.erro && (
          <pre>Error: {JSON.stringify(cep.status, undefined, 2)}</pre>
        )}
      </div>
      <input
        type="text"
        value={value}
        onChange={e => setValue(e.target.value)}
      />
      <button onClick={handleClickFindCep}>Busca de CEP</button>
    </div>
  );
};
export default App;

This hook is created using create-react-hook.

Package Sidebar

Install

npm i cep-hook

Weekly Downloads

9

Version

1.0.7

License

MIT

Unpacked Size

60.9 kB

Total Files

13

Last publish

Collaborators

  • fulviocanducci