api-hooks-react
v1.0.2
Published
This package will help you to provide some boilerplate code to call API's in a react app using hooks
Downloads
7
Readme
This package will help you to provide some boilerplate code to call API's in a react app using hooks
ENV variable
In your env file add a variable REACT_APP_API_URL = your api base url
Example - REACT_APP_API_URL = http://xyz.com/api
useGetData
To get the data from the API just use the useGetData hook and provide the API path Example-> {isLoading, data, error} = useGetData('/posts') as you can see in the above example it returns these states isLoading, data, error.
useCreate
For POST
method just use the useCreate hook and provide the API path
Example-> {isLoading, data, error, execute} = useCreate('/posts')
it provides a execute function to hit the POST api.
useUpdate
For PATCH
method just use the useUpdate hook and provide the API path
Example-> {isLoading, data, error, execute} = useUpdate('/posts')
it provides a execute function to hit the PATCH api.
useDelete
For DELETE
method just use the useDelete hook and provide the API path
Example-> {isLoading, data, error, execute} = useDelete('/posts')
it provides a execute function to hit the DELETE api.