Function useNullableState

  • This function is a react hook for state of type of your choosing. It comes with two memoized functions, one for setting state and one for clearing it.

    The items returned in the array can be destructured and named whatever you like:

    import { useNullableState } from '@oneblink/apps-react'

    const startingProfile = {
    name: 'Forest Gump',
    profession: 'Military, Athlete, Other',
    }

    const [userProfile, setUserProfile, unsetUserProfile] =
    useBooleanState(startingProfile)

    setUserProfile can then be called with an object of type T like:

    setUserProfile({
    name: 'Walter White',
    profession: 'Chemistry Teacher (Secondary School), Other',
    })

    And unsetUserProfile can be called like:

    unsetUserProfile()
    

    Type Parameters

    • T

      The type of the state

    Parameters

    • defaultValue: null | T

    Returns [state: T | null, setState: React.Dispatch<React.SetStateAction<T | null>>, clearState: (() => void)]