From 3c6465ded2b7da72f75fe443ce6afb2b4da4a205 Mon Sep 17 00:00:00 2001 From: John Chipps-Harding Date: Sat, 28 Sep 2019 00:16:46 +0100 Subject: [PATCH 1/3] Documentation Changes --- CHANGELOG.md | 4 ++++ README.md | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d20d2..414e5cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project are documented in this file. +## Unreleased + +- Changed: Documentation. + ## 0.3.0 - Changed: Input arguments now a configuration object. diff --git a/README.md b/README.md index a1d66fa..b3644db 100755 --- a/README.md +++ b/README.md @@ -8,14 +8,17 @@ A simple react hook for loading data from an api with polling support. ## Introduction -If you need a simple way to load data quickly this is for you. It allows you to very easily request data from any endpoint and have it avaliable in your React application. +If you need a simple way to load data quickly this is for you. It allows you to very easily request data from any endpoint and have it available in your React application. You can optionally specify a polling interval and manually trigger a refresh. It also gracefully cancels any open requests if you decide to change the URL and restarts timers if the polling interval changes. ```javascript -const { data, loading, changed, error, refresh } = useApi({ - apiEndpoint: "https://some-api.com", - pollInterval: 10000 +const { data, loading, error, refresh } = useApi({ + apiEndpoint: "https://some-api.com/api", + pollInterval: 10000, + payload: { keywords: "hello" }, + method: "post", + changed: data => console.log("The data changed!", data) }); ``` @@ -87,8 +90,8 @@ const PeopleSearch = () = { ### Input - `apiEndpoint` - A URL to request data from. -- `pollInterval` - How often to re-request updated data. Pass 0 to disable polling (the default behaviour). -- `payload` - A data object to send in the request. If we are performing a GET request, it is appended into the querystring (e.g. `?keywords=hello`). If it is a POST request it is sent in the request body as JSON. +- `pollInterval` - How often to re-request updated data. Pass 0 to disable polling (the default behavior). +- `payload` - A data object to send with the request. If we are performing a GET request, it is appended into the querystring (e.g. `?keywords=hello`). If it is a POST request it is sent in the request body as JSON. - `method` - Set the request type, either `get` or `post`. (defaults to `get`) - `changed`: A function that is called if the data actually changed during the request. If this is specified, use-api does extra checking and compares old and new data. If data does not change, new data is not propagated and a redraw is saved. Please note, this may have performance repercussions if the data is large as it performs a deep comparison between new and old data to determine if they are equivalent. From 159c1b6b85d6e8794f23d5bf819bf63861194707 Mon Sep 17 00:00:00 2001 From: John Richard Chipps-Harding Date: Tue, 1 Oct 2019 05:10:12 -0700 Subject: [PATCH 2/3] Update README.md Co-Authored-By: Marcel Kornblum --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3644db..ea4958f 100755 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ const PeopleSearch = () = { ### Input - `apiEndpoint` - A URL to request data from. -- `pollInterval` - How often to re-request updated data. Pass 0 to disable polling (the default behavior). +- `pollInterval` - How often to re-request updated data. Pass 0 to disable polling (the default behaviour). - `payload` - A data object to send with the request. If we are performing a GET request, it is appended into the querystring (e.g. `?keywords=hello`). If it is a POST request it is sent in the request body as JSON. - `method` - Set the request type, either `get` or `post`. (defaults to `get`) - `changed`: A function that is called if the data actually changed during the request. If this is specified, use-api does extra checking and compares old and new data. If data does not change, new data is not propagated and a redraw is saved. Please note, this may have performance repercussions if the data is large as it performs a deep comparison between new and old data to determine if they are equivalent. From e1f63208dccd50482850082b0993324912193e0a Mon Sep 17 00:00:00 2001 From: John Chipps-Harding Date: Tue, 1 Oct 2019 13:12:04 +0100 Subject: [PATCH 3/3] Mention required/optional arguments --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ea4958f..09936a6 100755 --- a/README.md +++ b/README.md @@ -89,11 +89,11 @@ const PeopleSearch = () = { ### Input -- `apiEndpoint` - A URL to request data from. -- `pollInterval` - How often to re-request updated data. Pass 0 to disable polling (the default behaviour). -- `payload` - A data object to send with the request. If we are performing a GET request, it is appended into the querystring (e.g. `?keywords=hello`). If it is a POST request it is sent in the request body as JSON. -- `method` - Set the request type, either `get` or `post`. (defaults to `get`) -- `changed`: A function that is called if the data actually changed during the request. If this is specified, use-api does extra checking and compares old and new data. If data does not change, new data is not propagated and a redraw is saved. Please note, this may have performance repercussions if the data is large as it performs a deep comparison between new and old data to determine if they are equivalent. +- `apiEndpoint` : Required - A URL to request data from. +- `pollInterval` : Optional - How often to re-request updated data. Pass 0 to disable polling (the default behaviour). +- `payload` : Optional - A data object to send with the request. If we are performing a GET request, it is appended into the querystring (e.g. `?keywords=hello`). If it is a POST request it is sent in the request body as JSON. +- `method` : Optional - Set the request type, either `get` or `post`. (defaults to `get`) +- `changed` : Optional - A function that is called if the data actually changed during the request. If this is specified, use-api does extra checking and compares old and new data. If data does not change, new data is not propagated and a redraw is saved. Please note, this may have performance repercussions if the data is large as it performs a deep comparison between new and old data to determine if they are equivalent. ### Output