delete dead code/comments & add useRequest docstring

This commit is contained in:
Keith Grant
2020-02-03 09:43:06 -08:00
parent 370a7f9b25
commit 638e8c7add
3 changed files with 13 additions and 4 deletions

View File

@@ -37,8 +37,6 @@ function Inventory({ i18n, setBreadcrumb }) {
useEffect(() => { useEffect(() => {
async function fetchData() { async function fetchData() {
try { try {
// TODO: delete next line
// setHasContentLoading(true);
const { data } = await InventoriesAPI.readDetail(match.params.id); const { data } = await InventoriesAPI.readDetail(match.params.id);
setBreadcrumb(data); setBreadcrumb(data);
setInventory(data); setInventory(data);

View File

@@ -31,8 +31,8 @@ function InventoryDetail({ inventory, i18n }) {
); );
useEffect(() => { useEffect(() => {
fetchInstanceGroups(inventory.id); fetchInstanceGroups();
}, [fetchInstanceGroups, inventory.id]); }, [fetchInstanceGroups]);
const deleteInventory = async () => { const deleteInventory = async () => {
await InventoriesAPI.destroy(inventory.id); await InventoriesAPI.destroy(inventory.id);

View File

@@ -1,5 +1,16 @@
import { useEffect, useState, useRef, useCallback } from 'react'; import { useEffect, useState, useRef, useCallback } from 'react';
/*
* The useRequest hook accepts a request function and returns an object with
* four values:
* request: a function to call to invoke the request
* result: the value returned from the request function (once invoked)
* isLoading: boolean state indicating whether the request is in active/in flight
* error: any caught error resulting from the request
*
* The hook also accepts an optional second parameter which is a default
* value to set as result before the first time the request is made.
*/
export default function useRequest(makeRequest, initialValue) { export default function useRequest(makeRequest, initialValue) {
const [result, setResult] = useState(initialValue); const [result, setResult] = useState(initialValue);
const [error, setError] = useState(null); const [error, setError] = useState(null);