babel-jsx-render-tools

0.0.6 • Public • Published

babel-jsx-render-tools

A babel plugin for render conditional in reactjs/native (like *ngIf of Angular)

Example:

<MyComponent renderIf={ item }>
  { item.title }
</MyComponent>

Result:

item && <MyComponent>{item.title}</MyComponent>

Summary

Introducing

It's a package that is inspirated in jsx-control-statements. Some features does not is present in jsx-control-statements, like a prop that makes conditional rendering easier and has the characteristic of the switch

Installation

npm i --save-dev babel-jsx-render-tools
// or
yarn add -D babel-jsx-render-tools

Add to .babelrc:

  {
    "plugins": [
        "module:babel-jsx-render-tools"
    ]
  }

renderIf prop

In whatever component, add prop renderId

<Component renderIf={true}><div>test</div></Component>
// result:
true && <Component><div>test</div></Component>

Switch Tag

use:

<Switch var={test}>
  <Case equal={1}>
    <span>It's one</span>
  </Case>
  <Case equal={2}>
    <span>It's two</span>
  </Case>
  <Default>
    <span>Unknown</span>
  </Default>
</Component>
// result:
test === 1? <span>It's one</span>: test === 2? <span>It's two</span>: <span>Unknown</span> 

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.62latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.62
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10
1.0.00

Package Sidebar

Install

npm i babel-jsx-render-tools

Weekly Downloads

2

Version

0.0.6

License

MIT

Unpacked Size

7.56 kB

Total Files

8

Last publish

Collaborators

  • misaelbsantos