0.0.2 • Published 12 months ago

react-conditional-fallback v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-conditional-fallback

npm downloads gzip size npm version PRs Welcome

Usage

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

import createConditionalFallback from 'react-conditional-fallback';

const optionalInitialValue = false;
const { Provider, useCondition, set, clear, ConditionalFallback } = createConditionalFallback(optionalInitialValue);

/*
 * `Provider` can hoist the state higher in the app, if omitted, the state exists at the level of the `ConditionalFallback`.
 * `useCondition` is a hook that returns the value of the condition
 * `set` sets the condition to `true`, note this does not need to be executed within the React context.
 * `clear` sets the condition to `false`, note this does not need to be executed within the React context.
 * `ConditionalFallback` operates similar to `React.Suspense` except that it renders the fallback when the condition is true (controlled via `set` and `clear`).
 * /

function App() {
  return (
    <ConditionalFallback fallback={<UnhappyPath />}>
      <HappyPath />
    </ConditionalFallback>
  );
}

This README was generated by anansi.

0.0.2

12 months ago

0.0.1

12 months ago