Skip to content

Commit bbc0cdf

Browse files
committed
Update readme
1 parent 396d6d8 commit bbc0cdf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ Creates a component, provider, and controls for handling conditions in a react a
1212
```javascript
1313
import createConditionalFallback from 'react-conditional-fallback';
1414

15+
const optionalInitialValue = false;
16+
const { Provider, useCondition, set, clear, ConditionalFallback } = createConditionalFallback(optionalInitialValue);
17+
18+
/*
19+
* `Provider` can hoist the state higher in the app, if omitted, the state exists at the level of the `ConditionalFallback`.
20+
* `useCondition` is a hook that returns the value of the condition
21+
* `set` sets the condition to `true`, note this does not need to be executed within the React context.
22+
* `clear` sets the condition to `false`, note this does not need to be executed within the React context.
23+
* `ConditionalFallback` operates similar to `React.Suspense` except that it renders the fallback when the condition is true (controlled via `set` and `clear`).
24+
* /
25+
1526
function App() {
1627
return (
17-
<></>
28+
<ConditionalFallback fallback={<UnhappyPath />}>
29+
<HappyPath />
30+
</ConditionalFallback>
1831
);
1932
}
2033
```

0 commit comments

Comments
 (0)