Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/raisiqueira/use-viacep

React hook to fetch Brazilian Zip Code using ViaCEP api.
https://github.com/raisiqueira/use-viacep

brazilian-utils cep react-hooks typescript viacep

Last synced: 11 days ago
JSON representation

React hook to fetch Brazilian Zip Code using ViaCEP api.

Awesome Lists containing this project

README

        

# useViaCep



![use-viacep](https://badgen.net/bundlephobia/minzip/@rsiqueira/use-viacep)

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

## Install

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

## Usage

```tsx
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

loading...

;
}

return (


setData(e.target.value)} />

);
};

ReactDOM.render(, 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](https://pnpm.io/workspaces) as workspace manager and package manager.
- [TSUP](https://tsup.egoist.dev/) as a TypeScript universal package.
- [Vitest](https://vitest.dev/) as a test runner.
- [Size Limit](https://github.com/ai/size-limit) as a size limit plugin.
- [Prettier](https://prettier.io/) as a code formatter.
- [ESLint](https://eslint.org/) as a code linter.

### Using the Playground

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

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

The command will run the example project with [Vite](https://vitejs.dev/).

## Sponsors

[![Sponsors](https://cdn.jsdelivr.net/gh/raisiqueira/static@master/sponsors.svg)](https://github.com/sponsors/raisiqueira)

## License

MIT @ Rai Siqueira