UNPKG

@rest-api/react-models

Version:

[![npm version](https://img.shields.io/npm/v/@rest-api/react-models)](https://www.npmjs.com/package/@rest-api/react-models) [![codecov](https://codecov.io/gh/hector7/rest-api-react-models/branch/master/graph/badge.svg)](https://codecov.io/gh/hector7/rest-

58 lines (57 loc) 2 kB
import { UrlCallbackParam, RestModel } from ".."; import { Schema, StringOrNumberKeys } from "../../Schema"; import { HttpError } from '../../../../'; export declare type UseGetByIdResult<Item> = { item: Item | null; initialized: boolean; loading: boolean; invalidated: boolean; error: HttpError | null; }; export declare type UseGetByIdPopulatedResult<PartialItem, PopulatedItem> = { populated: true; invalidated: boolean; initialized: boolean; error: HttpError | null; loading: boolean; item: PopulatedItem; } | { item: PartialItem | null; loading: boolean; initialized: boolean; populated: false; invalidated: boolean; error: HttpError | null; }; export default class BasicIdRestModel<S extends Schema<any> = any, IdKey extends StringOrNumberKeys<S['RealType']> & StringOrNumberKeys<S['PopulatedType']> & string = any> extends RestModel<{}, S, IdKey, any, any> { constructor(basicRestModel: RestModel<{}, S, any, any, any>, id: IdKey, url: UrlCallbackParam<{}>); useInvalidate(id: S["RealType"][IdKey]): () => void; useInvalidateAll(): () => void; useFetchByIdIfNeeded(id: S["RealType"][IdKey]): void; useGetById(id: S["RealType"][IdKey]): { redirect: () => void; item: S["RealType"] | null; initialized: boolean; loading: boolean; invalidated: boolean; error: HttpError | null; }; useFetchByIdPopulatedIfNeeded(id: S["PopulatedType"][IdKey]): void; useGetByIdPopulated(id: S["PopulatedType"][IdKey]): { redirect: () => void; populated: true; invalidated: boolean; initialized: boolean; error: HttpError | null; loading: boolean; item: S["FullPopulatedType"]; } | { redirect: () => void; item: S["PopulatedType"] | null; loading: boolean; initialized: boolean; populated: false; invalidated: boolean; error: HttpError | null; }; }