@rsiqueira/use-viacep
TypeScript icon, indicating that this package has built-in type declarations

1.5.3 • Public • Published

useViaCep

use-viacep

React hook to fetch Brazilian CEP's using ViaCEP api.

Install

Use your prefer package manager

npm i --save @rsiqueira/use-viacep
# or
yarn add @rsiqueira/use-viacep
# or
pnpm add @rsiqueira/use-viacep

Usage

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import useViaCep from '@rsiqueira/use-viacep';

const App = () => {
  const [data, setData] = React.useState('');
  const { cep, loading, error } = useViaCep(data);

  if (loading) {
    return <p>loading...</p>;
  }

  return (
    <div>
      <input placeholder="cep" onChange={(e) => setData(e.target.value)} />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));

Contributing

Clone this repository and run pnpm install. If you don't have pnpm, install it with npm install -g pnpm.

Folder structure

  • example - A folder with an example project. Think as playground.
  • lib - The source of @rsiqueira/use-viacep.

What is in this repository?

  • PNPM as workspace manager and package manager.
  • TSUP as a TypeScript universal package.
  • Vitest as a test runner.
  • Size Limit as a size limit plugin.
  • Prettier as a code formatter.
  • ESLint as a code linter.

Using the Playground

In the root of the repository, run the following command:

pnpm run dev # to build the library (with --watch flag)
pnpm -F example dev

The command will run the example project with Vite.

Sponsors

Sponsors

License

MIT @ Rai Siqueira

Package Sidebar

Install

npm i @rsiqueira/use-viacep

Weekly Downloads

59

Version

1.5.3

License

MIT

Unpacked Size

11.3 kB

Total Files

8

Last publish

Collaborators

  • rsiqueira