New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

babel-plugin-jsx-for-directive

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-for-directive

[![GitHub stars](https://img.shields.io/github/stars/HuQingyang/babel-plugin-jsx-for-directive.svg?style=social&label=Stars&style=plastic)](https://github.com/HuQingyang/babel-plugin-jsx-for-directive) [![GitHub forks](https://img.shields.io/github/forks/

latest
Source
npmnpm
Version
0.0.6
Version published
Weekly downloads
11
-26.67%
Maintainers
1
Weekly downloads
 
Created
Source

Using "for" directive in JSX

GitHub stars GitHub forks npm npm npm

A easy-to-use "for" directive solution for front-end frameworks using JSX like React.

See Also:

1. Install

npm install --save-dev babel-plugin-jsx-for-directive

2. Basic Usage

Edit your .babelrc file:

{
  "plugins": [
    "jsx-for-directive"
  ]
}

In your jsx file:

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            languages: ['JavaScript', 'TypeScript', 'Python', 'Rust', 'Scala']
        }
    }

    render() { return (
        <div>
            <ul>
                <li for={lan in this.state.languages}>{lan}</li>
            </ul>
        </div>
    )}
}

3. Usage with "index"

In your jsx file:

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            languages: ['JavaScript', 'TypeScript', 'Python', 'Rust', 'Scala']
        }
    }

    render() { return (
        <div>
            <ul>
                <li
                    for={(lan, index) in this.state.languages}
                    key={index}
                >{lan}</li>
            </ul>
        </div>
    )}
}

4. Usage with custom attribute name

Edit your .babelrc file:

{
  "plugins": [
    "jsx-for-directive", 
    { 
      "attrName": "r-for" 
    }
  ]
}

In your jsx file:

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            languages: ['JavaScript', 'TypeScript', 'Python', 'Rust', 'Scala']
        }
    }

    render() { return (
        <div>
            <ul>
                <li r-for={lan in this.state.languages}>{lan}</li>
            </ul>
        </div>
    )}
}

Keywords

JSX

FAQs

Package last updated on 14 Aug 2018

Related posts