# babel-plugin-react-directive **Repository Path**: evolify/babel-plugin-react-directive ## Basic Information - **Project Name**: babel-plugin-react-directive - **Description**: Use directive in React. - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2018-08-31 - **Last Updated**: 2022-03-26 ## Categories & Tags **Categories**: react-extensions **Tags**: None ## 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}
) } ```