usegardevoir
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published


Using SWR from Vercel as dependency, Gardevoir helps you define your routes and map them to specific components with ease.

How to use :

  1. Create a config file :
import { GardevoirReturnOptions } from "usegardevoir";
const config  = {
    getPokemon : (FetchOptions, SwrOptions) 
      : GardevoirReturnOptions  => {
        const {name} = FetchOptions || "gardevoir";
        return {
            url : `https://pokeapi.co/api/v2/pokemon/${name}`,
            revalidateIfStale : true,
            revalidateOnFocus : true,
            ...SwrOptions
        }
    }
}
export default config;
  1. Create a hook to get the react callback function based on your config file.
import initializeGardevoir from 'usegardevoir';
import config from './config';
function useGardevoir(){
    const gardevoirCb = initializeGardevoir(config);
    return gardevoirCb;
};
export default useGardevoir;
  1. Inside your component run the hook.
  const swr = useGardevoir();
  const data = swr('getPokemon',{
    FetchOptions : {
      name : 'ditto'
    },
    SwrOptions : {
      // if needed
    }
  })

Both FetchOptions and SwrOptions are optional, SwrOptions retrieve the types from SwrConfiguration.

Package Sidebar

Install

npm i usegardevoir

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

14.8 kB

Total Files

15

Last publish

Collaborators

  • neaguio