@mongez/react-atom
Version:
A simple state management tool for React Js.
121 lines (120 loc) • 2.73 kB
text/typescript
import { ReactAtom } from "./types.mjs";
import { ReactNode } from "react";
//#region ../@mongez/react-atom/src/helpers.d.ts
type OpenAtomActions = {
/**
* Toggle open state
*/
toggle: () => void;
/**
* Mark as opened
*/
open: () => void;
/**
* Mark as closed
*/
close: () => void;
/**
* Listen and get the opened state
*/
useOpened: () => boolean;
};
/**
* Open atom type
*/
type OpenAtomType = {
opened: boolean;
} & OpenAtomActions;
/**
* Create a boolean atom
*/
declare function openAtom(key: string, defaultOpened?: boolean): ReactAtom<boolean, OpenAtomActions>;
type LoadingAtomActions = {
/**
* Start loading
*/
startLoading: () => void;
/**
* Stop loading
*/
stopLoading: () => void;
/**
* Toggle loading
*/
toggleLoading: () => void;
};
type LoadingAtom = ReactAtom<boolean, LoadingAtomActions>;
/**
* Create a loading atom
*/
declare function loadingAtom(key: string, defaultLoading?: boolean): any;
/**
* Fetching atom type
*/
type FetchingAtomType<DataType, PaginationType> = {
/**
* Loading state
*/
isLoading: boolean;
/**
* Fetched data
*/
data: DataType | null;
/**
* Pagination data
*/
pagination?: PaginationType;
/**
* Fetching error
*/
error: any;
};
type FetchingAtomActions<DataType, PaginationType> = {
/**
* Start loading
*/
startLoading: () => void;
/**
* Stop loading
*/
stopLoading: () => void;
/**
* Mark data as fetched successfully, this will mark loading as false and set data
*/
success: (data: DataType, pagination?: PaginationType) => void;
/**
* Mark data as fetched successfully, this will mark loading as false and set data
*/
failed: (error: ReactNode) => void;
/**
* Used only with arrays, this will append data to the current data and mark loading as false
*/
append: (data: DataType) => void;
/**
* Used only with arrays, this will prepend data to current data and mark loading as false
*/
prepend: (data: DataType) => void;
/**
* Get and use loading state
*/
useLoading: () => boolean;
/**
* Get and use data
*/
useData: () => DataType | null;
/**
* Get and use error
*/
useError: () => ReactNode;
/**
* Get and use pagination
*/
usePagination: () => PaginationType | undefined;
};
/**
* Create a fetching atom
*/
declare function fetchingAtom<DataType = any, PaginationType = any>(key: string, defaultValue?: DataType | null, defaultFetching?: boolean): any;
//#endregion
export { FetchingAtomActions, FetchingAtomType, LoadingAtom, LoadingAtomActions, OpenAtomActions, OpenAtomType, fetchingAtom, loadingAtom, openAtom };
//# sourceMappingURL=helpers.d.mts.map