1.1.10 • Published 1 year ago

react-jsx-match v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-jsx-match

Allow conditional matching in React JSX.

Install

npm i react-jsx-match

or

yarn add react-jsx-match

Usage

import { Case, Else, Falsy, Match, Truthy, Render } from "react-jsx-match";

function Example() {
  const variable: number = 100; // variable can be any

  return (
    <>
      <Match expr={variable}>
        {/* Match exact values */}
        <Case val={0}>Zero</Case>
        <Case val={100}>A hundred</Case>

        {/* loose means `==` */}
        <Case val="1" loose>
          One
        </Case>

        {/* val can be a callback */}
        <Case val={(num: number) => num === 4}>Four</Case>

        {/* Match truthy values */}
        <Truthy>True</Truthy>

        {/* Match falsy values */}
        <Falsy>False</Falsy>

        {/* If nothing above matches... */}
        <Else>Everything else.</Else>
      </Match>

      {/* Render children only if when condition is truthy */}
      <Render when={variable > 100}>More than a hundred</Render>
    </>
  );
}

Development

npm i
npm run build
npm run test
npm run coverage
1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago