2.0.0 • Published 1 year ago

react-http-provider v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

react-http-provider

Installation

write this command after download requires packages

npm install --save react-http-provider

Usage

for using the library after install the package you should follow theses steps

1 - create store file for storing authentication states and use { authStoreBuilder } to build the store

import {authStoreBuilder} from 'react-http-provider';

const {AuthProvider,loginAction,logoutAction,useAuthDispatch,useAuthStore} = authStoreBuilder<{id:string,userName:string,token:string}>({
  getToke() {
    return localStorage.getItem('token');
  },
  removeToken(){
    localStorage.removeItem('token');
  },
  setToken(token) {
    localStorage.setItem('token',token);
  },
});


export {
  AuthProvider,
  loginAction,
  logoutAction,
  useAuthDispatch,
  useAuthStore
}

2 - create useHttp file to build custome http hook

import { logoutAction, useAuthDispatch } from "auth/store";
import { httpProviderBuilder } from "react-http-provider";


const useHttp = httpProviderBuilder({
  baseUrl:'https://localhost:7160',
  defaultApplyError(error){
    console.error(error);
  },
  getToken(){
    return localStorage.getItem('token');
  },
  refreshToken(respones) {
    
  },
  dispatchHook:useAuthDispatch,
  logoutAction:logoutAction
});

export default useHttp;
2.0.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago