Appearance
isDefined
Non-nullish checking type guard for React ref objects and plain values
Demo
Usage
tsx
import { isDefined } from '@reause/shared'
import { useRef } from 'react'
const example = useRef(Math.random() ? 'example' : undefined) // RefObject<string | undefined>
if (isDefined(example))
example.current // string — narrowed by the type guardType Declarations
ts
export type IsDefinedReturn = boolean
export function isDefined<T>(v: RefObject<T>): v is RefObject<Exclude<T, null | undefined>>
export function isDefined<T>(v: T): v is Exclude<T, null | undefined>