babel-plugin-react-native-classname-to-style
Transform JSX className
property to style
property in react-native.
Usage
Step 1: Install
yarn add --dev babel-plugin-react-native-classname-to-style
or
npm install --save-dev babel-plugin-react-native-classname-to-style
.babelrc
Step 2: Configure {
"presets": [
"react-native"
],
"plugins": [
"react-native-classname-to-style"
]
}
Syntax
Single class
Example:
<Text = />
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
...or with className
and style
:
<Text = = />
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
Multiple classes
[styles.class1, styles.class2].join(" ")
syntax
Using Example:
<Text = />
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
...or with className
and style
:
<Text = =/>
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
Using template literal syntax
Example:
<Text = />
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
...or with className
and style
:
<Text = =/>
↓ ↓ ↓ ↓ ↓ ↓
<Text = />
Using ternary operator
Example:
<Text = />
↓ ↓ ↓ ↓ ↓ ↓
<Text = />