Babel plugin that adds an `display-if` attribute to JSX elements to conditionally render them, inspired by Angular's ng-if. v3.0.0 (latest) is a stable release with no active development. It transforms `<Comp display-if={condition} />` into `{condition && <Comp />}`, making conditional rendering more readable for non-developers. Compared to inline ternaries or helper functions, this plugin provides a declarative, template-like syntax. Only compatible with Babel 7+ and requires the JSX transform. Minimal footprint with no runtime dependencies.
npm install babel-plugin-jsx-display-ifVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the Babel plugin in .babelrc and use the display-if attribute in a JSX component.
Use a single conditional expression or wrap with a fragment.
Upgrade Babel to version 7 or higher.
Use lowercase attribute name: `display-if={condition}`.Run `npm install --save-dev babel-plugin-jsx-display-if`
Ensure Babel 7+ and appropriate presets (e.g., @babel/preset-react) are installed.