fix: Refactor hover previews to reduce false positives (#6091)

This commit is contained in:
Tom Moor
2023-10-29 18:31:12 -04:00
committed by GitHub
parent 90bc60d4cf
commit 6b13a32234
9 changed files with 265 additions and 212 deletions

View File

@@ -1,9 +1,19 @@
import * as React from "react";
export default function usePrevious<T>(value: T): T | void {
/**
* A hook to get the previous value of a variable.
*
* @param value The value to track.
* @param onlyTruthy Whether to include only truthy values.
* @returns The previous value of the variable.
*/
export default function usePrevious<T>(value: T, onlyTruthy = false): T | void {
const ref = React.useRef<T>();
React.useEffect(() => {
if (onlyTruthy && !value) {
return;
}
ref.current = value;
});

View File

@@ -16,7 +16,7 @@ type RequestResponse<T> = {
* A hook to make an API request and track its state within a component.
*
* @param requestFn The function to call to make the request, it should return a promise.
* @returns
* @returns An object containing the request state and a function to start the request.
*/
export default function useRequest<T = unknown>(
requestFn: () => Promise<T>