https://github.com/nozzlegear/railway-react
React components for working with @nozzlegear/railway's functional helpers.
https://github.com/nozzlegear/railway-react
Last synced: 3 months ago
JSON representation
React components for working with @nozzlegear/railway's functional helpers.
- Host: GitHub
- URL: https://github.com/nozzlegear/railway-react
- Owner: nozzlegear
- License: mit
- Created: 2019-05-19T21:41:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-07-23T03:32:17.000Z (about 3 years ago)
- Last Synced: 2025-03-06T02:47:52.089Z (7 months ago)
- Language: TypeScript
- Size: 115 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @nozzlegear/railway-react
This is a collection of React components to complement the functional helpers found in [@nozzlegear/railway](https://github.com/nozzlegear/railway).
## Installation
```sh
yarn install @nozzlegear/railway @nozzlegear/railway-react
```## Usage
### `Option`
**Aliases**: Option, OptionComponent, Maybe, MaybeComponent
The `Option` component is a simple way to render a React component when the value of an `Option` is Some:
```tsx
import { Option } from "@nozzlegear/railway";
import { OptionComponent } from "@nozzlegear/railway-react";const myOption = Option.ofSome("Hello world");
{value =>
Message is: {value}}```
The component will only call the render function (and therefore will only render) if the value is Some. If the value is None, the function will not be called and an empty React fragment (`<>>`) will be returned instead.
### `If`
The `If` component only renders its children if the condition is true.
```tsx
import { If } from "@nozzlegear/railway-react";const value = true;
{"Only renders if value is true."}
```
### `Unless`
The `Unless` component is the inverse of the `If` component; it will only render its children when the condition is false.
```tsx
import { Unless } from "@nozzlegear/railway-react";const value = false;
{"Only renders if value is false."}
```