Skip to content

Commit 080cdd2

Browse files
committed
Restructure styling text once again
1 parent 1b2a281 commit 080cdd2

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

pages/docs/react/latest/styling.mdx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ canonical: "/docs/react/latest/styling"
66

77
# Styling
88

9-
There are many different approaches on how to do styling in React, such as:
9+
React comes with builtin support for inline styles, but there are also a number of third party libraries for styling React components. You might be comfortable with a specific setup, like:
1010

11-
- Inline Styles (`style=...`)
1211
- Global CSS / CSS modules
13-
- CSS utility libraries (`tailwindcss`, `tachyons`, etc.)
14-
- CSS-in-JS (such as `styled-components`, `emotion`, etc.)
12+
- CSS utility libraries (`tailwindcss`, `tachyons`, `bootstrap` etc.)
13+
- CSS-in-JS (`styled-components`, `emotion`, etc.)
1514

16-
There's no right or wrong when choosing a styling strategy, and each method has its up- and downsides. This page will give you some pointers on how to style your ReScript React components in your preferred style.
15+
If they work in JS then they almost certainly work in ReScript. In the next few sections, we've shared some ideas for working with popular libraries. If you're interested in working with one you don't see here, search the [package index](https://rescript-lang.org/packages) or post in [the forum](https://forum.rescript-lang.org).
1716

1817

1918
## Inline Styles
@@ -80,11 +79,8 @@ let app = <div className={styles["root"]} />
8079

8180
## CSS Utility Libraries
8281

83-
There are a number of third party libraries for styling React components and you might be comfortable with a specific setup. If they work in JS then they almost certainly work in ReScript. Below, we've shared some ideas for working with popular libraries. If you're interested in working with one you don't see here, search the [package index](https://rescript-lang.org/packages) or post in [the forum](https://forum.rescript-lang.org)
84-
8582
### Tailwind
8683

87-
8884
CSS utility libraries like [TailwindCSS](https://tailwindcss.com) usually require some globally imported CSS.
8985

9086
First, create your TailwindCSS main entrypoint file:
@@ -137,9 +133,9 @@ When using the [Tailwind VSCode plugin](https://tailwindcss.com/docs/intellisens
137133

138134
## CSS-in-JS
139135

140-
Currently there are no official recommendations for CSS-in-JS yet due to the wildly different approaches on how to bind to CSS-in-JS libraries (going from simple to very advanced).
136+
There's no way we could recommend a definitive CSS-in-JS workflow, since there are many different approaches on how to bind to CSS-in-JS libraries (going from simple to very advanced).
141137

142-
The most minimalistic approach is to create simple bindings to e.g. [`emotion`](https://emotion.sh/docs/introduction) (as described [here](https://github.com/bloodyowl/rescript-react-starter-kit/blob/eca7055c59ba578b2d1994fc928d8f541a423e74/src/shared/Emotion.res)):
138+
For demonstration purposes, let's create some simple bindings to e.g. [`emotion`](https://emotion.sh/docs/introduction) (as described [here](https://github.com/bloodyowl/rescript-react-starter-kit/blob/eca7055c59ba578b2d1994fc928d8f541a423e74/src/shared/Emotion.res)):
143139

144140
```res
145141
// src/Emotion.res
@@ -152,7 +148,7 @@ The most minimalistic approach is to create simple bindings to e.g. [`emotion`](
152148
@module("@emotion/css") external injectGlobal: string => unit = "injectGlobal"
153149
```
154150

155-
This will give you straight-forward access to the `emotion` apis. Here's how you'd use them in your app code:
151+
This will give you straight-forward access to `emotion`'s apis. Here's how you'd use them in your app code:
156152

157153
```res
158154
let container = Emotion.css({
@@ -178,7 +174,7 @@ module Styles = {
178174
let app = <div className={Styles.container} />
179175
```
180176

181-
Please note that this approach will not typecheck for invalid css attribute names. If you e.g. want to make sure that only valid CSS attributes are being passed, you could define your `css` function like this as well:
177+
Please note that this approach will not check for invalid css attribute names. If you e.g. want to make sure that only valid CSS attributes are being passed, you could define your `css` function like this as well:
182178

183179
```res
184180
@module("@emotion/css") external css: React.Style.t => string = "css"
@@ -192,9 +188,6 @@ let app = <div
192188
```
193189

194190
Here we used the already existing `React.Style.t` type to enforce valid CSS attribute names.
195-
196-
**Rule of thumb:** There's a spectrum on how type-safe an API might be, so choose a solution that fits to your team's needs.
197-
198191
Last but not least, you can also bind to functions that let you use raw CSS directly:
199192

200193
```res
@@ -206,4 +199,4 @@ let container = Emotion.rawCss(`
206199
let app = <div className={container} />
207200
```
208201

209-
For more CSS-in-JS ideas, you can also check out related discussions, or start a new topic on our [forum](https://forum.rescript-lang.org).
202+
Please keep in mind that there's a spectrum on how type-safe an API can be (while being more / less complex to handle), so choose a solution that fits to your team's needs.

0 commit comments

Comments
 (0)