Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.39 KB

File metadata and controls

53 lines (38 loc) · 1.39 KB

babel-plugin-react-native-unistyles

Experimental Babel plugin for React Native Unistyles to automatically inject useStyles hook whenever stylesheet is referenced.

Before transformation:

import { View } from "react-native";
import { createStyleSheet } from "react-native-unistyles";

function App() {
  return <View style={styles.container} />;
}

const styles = createStyleSheet({
  container: {
    width: 100,
    height: 100,
  }
});

After transformation:

import { View } from "react-native";
import { createStyleSheet, useStyles as _useStyles } from "react-native-unistyles";

function App() {
  const { styles: _styles } = useStyles(_stylesheet);
  return <View style={_styles.container} />;
}

const _stylesheet = createStyleSheet({
  container: {
    width: 100,
    height: 100,
  }
});

Installation

pnpm install -D babel-plugin-react-native-unistyles

After installing, make sure to update your Babel configuration by adding "babel-plugin-react-native-unistyles" to the plugins array. This allows Babel to apply the plugin during compilation and transform your code as needed.

Contributing

Contributions are welcome. Please submit your pull requests or open issues to propose changes or report bugs.