babel-plugin-jsx-for-directive
v0.0.6
Published
[](https://github.com/HuQingyang/babel-plugin-jsx-for-directive) [ {
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>
)}
}