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: over 1 year ago
JSON representation
React hook to fetch Brazilian Zip Code using ViaCEP api.
- Host: GitHub
- URL: https://github.com/raisiqueira/use-viacep
- Owner: raisiqueira
- License: mit
- Created: 2020-04-13T17:11:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-07T23:56:52.000Z (about 3 years ago)
- Last Synced: 2025-03-17T22:44:45.071Z (over 1 year ago)
- Topics: brazilian-utils, cep, react-hooks, typescript, viacep
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@rsiqueira/use-viacep
- Size: 504 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# useViaCep

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
[](https://github.com/sponsors/raisiqueira)
## License
MIT @ Rai Siqueira