babel-jsx-render-tools
A babel plugin for render conditional in reactjs/native (like *ngIf of Angular)
Example:
<MyComponent renderIf= item > itemtitle </MyComponent>
Result:
item && <MyComponent>itemtitle</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// oryarn add -D babel-jsx-render-tools
Add to .babelrc:
renderIf prop
In whatever component, add prop renderId
<Component =><div>test</div></Component>// result:true && <Component><div>test</div></Component>
Switch Tag
use:
<Switch => <Case => <span> one</span> </Case> <Case => <span> two</span> </Case> <Default> <span>Unknown</span> </Default></Component>// result:test === 1? <span> one</span>: test === 2? <span> two</span>: <span>Unknown</span>