Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/evolify/babel-plugin-react-directive

Use directive in React.
https://github.com/evolify/babel-plugin-react-directive

Last synced: 3 months ago
JSON representation

Use directive in React.

Awesome Lists containing this project

README

        

# babel-plugin-react-directive
Use directive in React.

Now you can use `r-if`、`r-for` in jsx.

## Usage:

1. Install: `yarn add babel-plugin-react-directive --dev`

2. Add to your .babelrc:

```
{
plugins:[
'react-directive'
]
}
```

### r-if:

* Before:

```jsx
render(){
const visible = true
return(


{
visible ?
content

: ''
}

)
}
```

* Now:

```jsx
render(){
const visible = true
return(


content


)
}
```

### r-for:

* Before:

```jsx
render(){
const list = [1, 2, 3, 4, 5]
return(


{
list.map((item,index)=>(
{item}

))
}

)
}
```

* Now:

```jsx
render(){
const list = [1, 2, 3, 4, 5]
return(


{/* auto set 'key' to the index */}
{item}

{/* or you can set the key manually */}
{item}


)
}
```