@ashraflabs/use-api
Version:
A simple and powerful custom React hook (useApi) that simplifies API requests with automatic loading and error states. Ideal for clean and maintainable data fetching in React components.
13 lines (12 loc) • 687 B
TypeScript
import { FormDataType } from "../types/FormDataType";
/**
* Converts an object to FormData, handling various data types including arrays and files.
* @template T The type of the input data, extending FormDataType.
* @param data The object to convert to FormData.
* @param removeNulls If true, excludes null or undefined values; otherwise, includes them as empty strings.
* @returns A FormData object containing the converted key-value pairs.
* @example
* const data = { name: "Test", image: new File(["content"], "test.png") };
* const formData = dataToFormData(data);
*/
export declare function dataToFormData<T extends FormDataType>(data: T, removeNulls?: boolean): FormData;