@nozzlegear/railway-react
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@nozzlegear/railway-react

This is a collection of React components to complement the functional helpers found in @nozzlegear/railway.

Installation

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:

import { Option } from "@nozzlegear/railway";
import { OptionComponent } from "@nozzlegear/railway-react";

const myOption = Option.ofSome("Hello world");

<OptionComponent value={myOption}>
    {value => <div>Message is: {value}</div>}
</OptionComponent>

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.

import { If } from "@nozzlegear/railway-react";

const value = true;

<If condition={value}>
    <p>{"Only renders if value is true."}</p>
</If>

Unless

The Unless component is the inverse of the If component; it will only render its children when the condition is false.

import { Unless } from "@nozzlegear/railway-react";

const value = false;

<Unless condition={value}>
    <p>{"Only renders if value is false."}</p>
</Unless>

Readme

Keywords

none

Package Sidebar

Install

npm i @nozzlegear/railway-react

Weekly Downloads

5

Version

3.0.0

License

MIT

Unpacked Size

9.91 kB

Total Files

9

Last publish

Collaborators

  • nozzlegear