Skip to content

Repository files navigation

react-conditional-fallback

npm downloadsgzip sizenpm versionPRs Welcome

Usage

Creates a component, provider, and controls for handling conditions in a react app.

importcreateConditionalFallbackfrom'react-conditional-fallback';constoptionalInitialValue=false;const{ Provider, useCondition, set, clear, ConditionalFallback }=createConditionalFallback(optionalInitialValue);/**`Provider`canhoistthestatehigherintheapp,ifomitted,thestateexistsatthelevelofthe`ConditionalFallback`.*`useCondition`isahookthatreturnsthevalueofthecondition*`set`setstheconditionto`true`,notethisdoesnotneedtobeexecutedwithintheReactcontext.*`clear`setstheconditionto`false`,notethisdoesnotneedtobeexecutedwithintheReactcontext.*`ConditionalFallback`operatessimilarto`React.Suspense`exceptthatitrendersthefallbackwhentheconditionistrue(controlledvia`set`and`clear`).*/functionApp(){return(<ConditionalFallbackfallback={<UnhappyPath/>}><HappyPath/></ConditionalFallback>);}

This README was generated by anansi.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages