React hook to fetch Brazilian CEP's using ViaCEP api.
npm i --save @rsiqueira/use-viacep # or yarn add @rsiqueira/use-viacep
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'));
Clone this repository and run pnpm install
. If you don't have pnpm, install it with npm install -g pnpm
.
example
- A folder with an example project. Think as playground.lib
- The source of@rsiqueira/use-viacep
.
- 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.
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.
MIT @ Rai Siqueira