Description
JSX Control Statements is a Babel plugin that adds basic control statements to JSX: conditionals and loops, written as component-like tags. It transforms those tags into plain JavaScript, so a conditional tag becomes a ternary expression that returns null when the condition is false. The plugin is aimed at developers coming to React from templating libraries such as Handlebars, who expect built-in looping and conditional syntax. The README explains that React does not include this by design, since JSX is syntactic sugar over JavaScript expressions, and this plugin keeps the same principle while making render functions easier to read. Its only dependency is Babel, and it works with React and React Native. The README also carries a warning: because it is a Babel plugin that changes your code, tools that read your source, such as static analysis and TypeScript, may not work with it. The README covers the If, Choose, For and With tags, linting with ESLint and Flow, and pure JavaScript alternatives that use && and map. The project is open source and hosted on GitHub.…
Highlights
- Conditionals and loops as JSX tags
- Compiles to plain JavaScript
- Works with React and React Native
- Only dependency is Babel
- ESLint and Flow linting notes
Ratings & Reviews
No ratings yet
Be the first to rate jsx-control-statements.
People also visit
jsx-control-statements FAQ
What does JSX Control Statements add?
If and For tags in JSX, plus Choose and With tags, which compile to ordinary JavaScript expressions.
How do I install it?
It is a Babel plugin. The README's Installation section covers adding it to your Babel setup.
Will it break my tooling?
It might. The README warns that tools that read your source, such as static analysis and TypeScript, may not work with code the plugin changes.
Is there an option without a plugin?
Yes. The README describes using && and map in plain JavaScript, and suggests that route if you want to stay on the well-trodden path.
Does it work with React Native?
Yes. The README says it is compatible with React and React Native.
What are the best jsx-control-statements alternatives?
Popular alternatives to jsx-control-statements include style-it, html-to-react and uncontrollable. See all jsx-control-statements alternatives























