@mongez/react-atom
Version:
A simple state management tool for React Js.
117 lines • 2.87 kB
TypeScript
import { ReactNode } from "react";
import { ReactAtom } from "./types";
export 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
*/
export type OpenAtomType = {
opened: boolean;
} & OpenAtomActions;
/**
* Create a boolean atom
*/
export declare function openAtom(key: string, defaultOpened?: boolean): ReactAtom<boolean, OpenAtomActions>;
export type LoadingAtomActions = {
/**
* Start loading
*/
startLoading: () => void;
/**
* Stop loading
*/
stopLoading: () => void;
/**
* Toggle loading
*/
toggleLoading: () => void;
};
export type LoadingAtom = ReactAtom<LoadingAtomActions> & LoadingAtomActions;
/**
* Create a loading atom
*/
export declare function loadingAtom(key: string, defaultLoading?: boolean): Atom<Value, import("./types").ReactActions<Value> & Actions>;
/**
* Fetching atom type
*/
export type FetchingAtomType<DataType, PaginationType> = {
/**
* Loading state
*/
isLoading: boolean;
/**
* Fetched data
*/
data: DataType | null;
/**
* Pagination data
*/
pagination?: PaginationType;
/**
* Fetching error
*/
error: any;
};
export 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
*/
export declare function fetchingAtom<DataType = any, PaginationType = any>(key: string, defaultValue?: DataType | null, defaultFetching?: boolean): Atom<Value, import("./types").ReactActions<Value> & Actions>;
//# sourceMappingURL=helpers.d.ts.map