Skip to content

raisiqueira/use-viacep

Repository files navigation

useViaCep

use-viacep

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

Install

npm i --save @rsiqueira/use-viacep # or yarn 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