UNPKG

r3bl-ts-utils

Version:

The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu

19 lines (18 loc) 922 B
import { ReactRef, StateHolder } from "./react-core-utils"; /** * Similar to [useState](https://reactjs.org/docs/hooks-reference.html#usestate) with some changes: * 1. Ensures that enclosing function component is mounted in order to update state. * 2. Returns an object instead of an array. * * @see https://reactjs.org/docs/hooks-reference.html#usestate * @param initialValue Make this the initial value for state. * @returns An object containing 2 items: the state, and a function that enables updating the * state if the component is not mounted. */ export declare const useStateSafely: <T>(initialValue: T) => StateHolder<T>; /** * Runs an effect just once (onComponentDidMount) which sets the ref (that's returned) to true when * the component is mounted. And false when it isn't (hasn't been mounted yet, or has been * unmounted). */ export declare const useIsComponentMounted: () => ReactRef<boolean>;