Skip to content

FVitor7/use-brApiCnpj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useBrazilApiCnpj

use-brapi-cnpj

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

Releases

No releases published

Packages

No packages published