tsx-conditionals
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

TSX Conditionals

Example

Codesandbox

tsx conditionals exposes two components:

For & If

Purpose

  • Eliminate exposed control flow logic in your components
  • Reduce mixing Javascript/Typescript and JSX/TSX in a view component
  • Improve readability

For replaces:

  • {data.map(item => <Component key={item.key} />)}
  • {data && data.map(item => <Component key={item.key} />)}

If replaces:

  • {open && <Component />}
  • {open ? <ComponentA /> : <ComponentB />}

Props

For props:

  • data: T[] | null
  • render: (item: T) => JSX.Element | React.FC

If props:

  • cond: boolean
  • then: JSX.Element
  • orElse: JSX.Element | null

Package Sidebar

Install

npm i tsx-conditionals

Weekly Downloads

10

Version

1.2.0

License

ISC

Unpacked Size

4.59 kB

Total Files

12

Last publish

Collaborators

  • ahvmckay