1.0.9 • Published 2 years ago
use-http-https v1.0.9
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?
First import in the file where you need to send http request
It is a react hook function so it cannot be used inside any nested function
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])
}