3.7.8 • Published 2 months ago

use-hook-api v3.7.8

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

Uses of use-hook-api

use-hook-api returns responseApi, cancelRequest, useApi, Axios

Usage/Examples

import { responseApi, cancelRequest, useApi, Axios } from 'use-hook-api'

Axios.defaults.baseURL='https://jsonplaceholder.typicode.com'

const getPostById=(id=1)=>{
    return responseApi(`/posts/${id}`,'get',null,{Content-Type:'application/json'})
}

const createPost=(data)=>{
    return responseApi(`/posts/${id}`,'post',data,{Content-Type:'application/json'})
}

//Fetch api on component render
export const showPost = () => {
const [,{data,loading,error,message}]=useApi(getPostById)

    console.log(data,loading,error,message)

}

//Fetch api on button click
export const showPostOnClick=()=>{
const [getApi,{data,loading,error,message}]=useApi()

console.log(data,loading,error,message)

    return(
        <button onClick={()=>getApi(getPostById(2))}>
        </button>
    )

}

//Post api on button click
export const showPostOnClick=()=>{
const [postApi,{data,loading,error,message}]=useApi()

console.log(data,loading,error,message)

    return(
        <button onClick={()=>postApi(createPost({userId:1,id:1,title:'test',body:'test body'}))}>
        </button>
    )

}


//Post api on button click and redirect
export const showPostOnClick=()=>{
const [postApi]=useApi()

console.log(data,loading,error,message)

const onButtonClick=()=>{
   const postData={userId:1,id:1,title:'test',body:'test body'}
   postApi(createPost(postData),(res)=>{
      if(!res.error) redirect('/url')
   })
}

    return(
        <button onClick={onButtonClick}>
        </button>
    )

}
3.7.8

2 months ago

3.7.7

2 months ago

3.7.6

3 months ago

3.7.5

3 months ago

3.7.4

3 months ago

3.7.3

3 months ago

3.7.2

3 months ago

3.6.9

3 months ago

3.6.8

3 months ago

3.7.1

3 months ago

3.7.0

3 months ago

3.6.6

4 months ago

3.6.5

4 months ago

3.6.7

4 months ago

3.6.4

5 months ago

3.6.2

7 months ago

3.6.1

7 months ago

3.6.0

7 months ago

3.6.3

7 months ago

3.5.13

10 months ago

3.5.12

10 months ago

3.5.11

10 months ago

3.5.10

10 months ago

3.5.7

10 months ago

3.3.9

10 months ago

3.5.6

10 months ago

3.3.8

10 months ago

3.5.5

10 months ago

3.3.7

10 months ago

3.1.9

10 months ago

3.5.4

10 months ago

3.3.6

10 months ago

3.1.8

10 months ago

3.5.9

10 months ago

3.5.8

10 months ago

3.4.0

10 months ago

3.2.2

10 months ago

3.0.4

12 months ago

3.2.1

10 months ago

3.0.3

12 months ago

3.2.0

10 months ago

3.0.2

12 months ago

3.0.1

12 months ago

3.4.4

10 months ago

3.2.6

10 months ago

3.0.8

11 months ago

3.4.3

10 months ago

3.2.5

10 months ago

3.0.7

11 months ago

3.4.2

10 months ago

3.2.4

10 months ago

3.0.6

11 months ago

3.4.1

10 months ago

3.0.5

11 months ago

3.4.10

10 months ago

3.0.0

12 months ago

3.4.8

10 months ago

3.4.7

10 months ago

3.2.9

10 months ago

3.4.6

10 months ago

3.2.8

10 months ago

3.4.5

10 months ago

3.2.7

10 months ago

3.4.9

10 months ago

3.3.1

10 months ago

3.1.3

10 months ago

3.3.0

10 months ago

3.1.2

10 months ago

3.1.1

11 months ago

3.1.0

11 months ago

3.5.3

10 months ago

3.3.5

10 months ago

3.1.7

10 months ago

3.5.2

10 months ago

3.3.4

10 months ago

3.1.6

10 months ago

3.5.1

10 months ago

3.3.3

10 months ago

3.1.5

10 months ago

3.5.0

10 months ago

3.3.2

10 months ago

3.1.4

10 months ago

2.0.0

1 year 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