react-conditional-fallback
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i react-conditional-fallback

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

33.7 kB

Total Files

25

Last publish

Collaborators

  • notwillk