README
useViaCep
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'));
Commands (for development only)
npm start # or yarn start
This builds to /dist
and runs the project in watch mode so any edits you save inside src
causes a rebuild to /dist
.
Then run the example inside another:
cd example
npm i # or yarn to install dependencies
npm start # or yarn start
To do a one-off build, use npm run build
or yarn build
.
To run tests, use npm test
or yarn test
.
Using the Playground
cd example
npm i # or yarn to install dependencies
npm start # or yarn start
The default example imports and live reloads whatever is in /dist
, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. No symlinking required!
License
MIT @ Rai Siqueira