1.0.9 • Published 2 years ago

use-http-https v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

use-http-https

A ready to use React hook to make http request easier and simpler

You dont have to think about async await in your code just follow the instruction

if not work feel free to send an email at: jah.hasant@gmail.com

Installation

use npm to install the package

npm install use-http-https

How to use?

  1. First import in the file where you need to send http request

  2. It is a react hook function so it cannot be used inside any nested function

  3. It returns an object of three properties so destructure the values like --

const {isLoading, error, sendRequest} = useHttpHttps()

isLoading is the current status of your request and if any error happens it will be available in error

sendRequest is a function it takes 2 arguments first is a object like --

sendRequst({url:"example.com", method:"POST", { "Content-Type": "application/json"}, body:{name:"name"}}

If you want to make a get request just pass the url

sendRequst({url:"example.com"})

the second argument of sendRequest function is another function that have the response of your request

Usage

import {useEffect} from "react"
import useHttpHttps from "use-http-https"

const App = ()=> {
const {isLoading, error, sendRequest} = useHttpHttps()

useEffect(()=>{

const applyData=(data)=>{
// do whatever you want with the data
console.log(data)
}

sendRequst({url:"example.com", method:"POST", { "Content-Type": "application/json"}, body:{name:"name"}}, applyData )

},[sendRequest])

}
1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago