Skip to content

Fabio-Dev-Bauru/use-data-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

use-data-web

React hook that manipulates request data from api. It give to you more productivity and you don't need every time create states in components in your application like isLoading, error and response data. Just pass the function to hook and you will have those states.

Getting started

Install the library using npm:

npm install use-data-web

Usage

import { useData } from "use-data-web";

// call the hook function
const {
    isLoading, // boolean that indicates if is loading the request api.
    data: branchs, // response from api typed by the type passed to the function
    error, // returns string if there was some error during request api
    forceUpdateData, // function that forces call data again
  } = useData<Type>({
    fn: () => getBranchs(), // put the function that returns data from api
    deps: [] // you can put dependencies to callback the function like use effect
    shouldRun: true // a boolean variable to determine if the fn should be run
  });

if (error) {
    console.log(error);
}

If you need revalidate the data you can call forceUpdateData function, for example:

  const handleSomething = () => {
    // to do something
    // forceUpdateData(); // here the hook will be called again and the data would be updated.
  }

Maintainers

License

The library is released under the MIT license. For more information see LICENSE.

If you has suggestion I'm open to talk about it.

About

React Hook for React Applications

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published