Skip to content

react-noui/react-conditional-fallback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 10, 2023
6e131cb · May 10, 2023

History

8 Commits
May 6, 2023
May 6, 2023
May 6, 2023
May 10, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 7, 2023
May 6, 2023
May 10, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023
May 6, 2023

Repository files navigation

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.