use-brapi-cnpj
v1.0.8
Published
React hook to fetch Brazilian CNPJ's using BrazilApi.
Downloads
3
Maintainers
Readme
useBrazilApiCnpj
React hook to fetch Brazilian CNPJ's using Brasil API.
Install
NPM
npm i use-brapi-cnpj
YARN
yarn add use-brapi-cnpj
Usage
import React, { useState } from "react";
import useBrApiCnpj from "use-brapi-cnpj";
function App() {
const [data, setData] = useState("");
const { cnpj, loading, error } = useBrApiCnpj(data);
if (loading) {
return <p>loading...</p>;
}
if (error) {
return <p>Aconteceu um erro ao tentar consultar este CNPJ!</p>;
}
return (
<div>
<div>
<p>CNPJ: {cnpj && cnpj.cnpj}</p>
<p>Razão Social: {cnpj && cnpj.razao_social}</p>
<p>Nome Fantasia: {cnpj && cnpj.nome_fantasia}</p>
<p>Número CNAE: {cnpj && cnpj.cnae_fiscal}</p>
<p>Descrição CNAE: {cnpj && cnpj.cnae_fiscal_descricao}</p>
</div>
<input placeholder="Cnpj" onChange={(e) => setData(e.target.value)} />
</div>
);
}
export default App;
Code Result
Commands (for development only)
npm start # or yarn 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 @Fábio Vitor