Skip to content

nullthrows

Carlos Alba edited this page Nov 21, 2020 · 1 revision

nullthrows

This is a simple utility function that throws an error when a value is null and can be used to null check values.

Best practice: Using this function at higher levels component parents, sources of data or directly where a nullish (possibly null) value is being pulled from is best. You don't want redundant or pointless nullthrows usages at lower levels (children) as a side note the earlier you can catch problems the better.

Here is an example of usage

....

type Props = ReadOnly<{
   nullish?: string
}>

function RenderTextComponent(props: Props) {
    return <h1> {nullthrows(props.nullish)} </h1>
}
Clone this wiki locally