-
Notifications
You must be signed in to change notification settings - Fork 30
chore: update readme #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update readme #175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,10 +13,12 @@ The goal of this library is to provide the most complete CSS support for React N | |||||
| ### Metro based projects | ||||||
|
|
||||||
| > [!TIP] | ||||||
| > All Expo and React Native Community CLI projects use Metro as the bundler, so this guide applies to them. | ||||||
| > Most React Native projects use Metro as the bundler. | ||||||
|
|
||||||
| You will need to add `withReactNativeCSS` to your Metro configuration. | ||||||
|
|
||||||
| #### Expo Projects | ||||||
|
|
||||||
| ```ts | ||||||
| import { getDefaultConfig } from "expo/metro-config"; | ||||||
| import { withReactNativeCSS } from "react-native-css/metro"; | ||||||
|
|
@@ -31,6 +33,17 @@ export default withReactNativeCSS(defaultConfig, { | |||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| #### Non-Expo Projects | ||||||
|
|
||||||
| `react-native-css` relies on the bundler to process CSS files. Currently only Expo provides a CSS asset pipeline. Since the Expo SDK is modular, you can add this functionality by just using the `@expo/metro-config` package. | ||||||
|
|
||||||
| Follow the Expo instructions, but replace the `expo` package with `@expo/metro-config`. | ||||||
|
|
||||||
| ```diff | ||||||
| - import { getDefaultConfig } from "expo/metro-config"; | ||||||
| + import { getDefaultConfig } from "@expo/metro-config"; | ||||||
| ``` | ||||||
|
|
||||||
| ### Other bundlers | ||||||
|
|
||||||
| `react-native-css` officially only supports Metro as the bundler, but we welcome community contributions to support other bundlers like Webpack, Vite or Turbopack. | ||||||
|
|
@@ -88,23 +101,42 @@ module.exports = withReactNativeCSS( | |||||
| ); | ||||||
| ``` | ||||||
|
|
||||||
| ### Via hooks | ||||||
| ### Via `styled` | ||||||
|
|
||||||
| You can also use the `styled` function to get styled components. | ||||||
|
|
||||||
| ```ts | ||||||
| import { View } from 'react-native'; | ||||||
| import { styled } from 'react-native-css'; | ||||||
|
|
||||||
| import "./styles.css"; | ||||||
|
|
||||||
| const MyView = styled(View) | ||||||
|
|
||||||
| export default function App() { | ||||||
| return ( | ||||||
| <MyView className="container"> | ||||||
| <MyView className="box" /> | ||||||
| </View> | ||||||
| ); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| #### `useCssElement` | ||||||
| ### Via hooks | ||||||
|
|
||||||
| You can also use the `useCssElement` hook. | ||||||
|
|
||||||
| ```ts | ||||||
| import { View as RNView } from 'react-native'; | ||||||
| import { View } from 'react-native'; | ||||||
| import { useCssElement } from 'react-native-css'; | ||||||
|
|
||||||
| export default function App() { | ||||||
| const Container = useCssElement(RNView, { | ||||||
| const Container = useCssElement(View, { | ||||||
| className: "container", | ||||||
| }); | ||||||
|
|
||||||
| const Box = useCssElement(RNView, { | ||||||
| className: "container", | ||||||
| const Box = useCssElement(View, { | ||||||
| className: "box", | ||||||
|
Comment on lines
+138
to
+139
|
||||||
| }); | ||||||
|
|
||||||
| return ( | ||||||
|
|
@@ -116,11 +148,11 @@ export default function App() { | |||||
| ``` | ||||||
|
|
||||||
| > [!IMPORTANT] | ||||||
| > The hook returns a React Element, not a style object. The element will work on all platforms and will correctly apply the React context needed to support all features of the library | ||||||
| > The hook returns a React Element, not a style object. | ||||||
|
|
||||||
| #### `useNativeCssStyle` | ||||||
|
|
||||||
| If you just require the style object, you can use the `useNativeCssStyle` hook: | ||||||
| If you just require the style object, you can use the `useNativeCssStyle` hook | ||||||
|
||||||
| If you just require the style object, you can use the `useNativeCssStyle` hook | |
| If you just require the style object, you can use the `useNativeCssStyle` hook: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 120 should use
</MyView>closing tag instead of</View>to match the opening<MyView>tag on line 118.