You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/website/pages/getting-started/native.mdx
+24-11Lines changed: 24 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Getting Started - OCaml
3
-
showAllLanguage: true
3
+
showAllLanguage: false
4
4
---
5
5
6
6
import { Callout } from"nextra/components";
@@ -116,7 +116,7 @@ let app =
116
116
</div>;
117
117
```
118
118
119
-
To generate the CSS on the server, you would need to use `<CSS.style_tag />`. This component will render a `<style>` with all generated stylesheet.
119
+
To generate the CSS on the server, you would need to use `<CSS.style_tag />`. This component will render a `<style>`tag with all the generated styles.
120
120
121
121
Given a `Page` component to simulate a real-world scenario:
122
122
@@ -133,10 +133,12 @@ module Page = {
133
133
}
134
134
```
135
135
136
-
If you're using dynamic CSS values, such as [dynamic-components](./dynamic-components) or [interpolation](./interpolation) based on runtime values. You would need to evaluate your app before extracting all the CSS.
136
+
## A note on missing classNames
137
+
138
+
If you're using dynamic CSS values, such as [dynamic-components](./dynamic-components) or [interpolation](./interpolation) based on runtime values, you would need to evaluate your app before extracting all the CSS. Let me explain it with a simple example:
137
139
138
140
```reason
139
-
module Component = {
141
+
module App = {
140
142
[@react.component]
141
143
let make = (~value) => {
142
144
let className = switch (value) {
@@ -148,12 +150,14 @@ module Component = {
148
150
};
149
151
```
150
152
151
-
This component needs to be rendered before the `CSS.style_tag` otherwise the `[%cx]` calls won't be added to the stylesheet, since they aren't being executed yet.
153
+
This component (App) needs to be rendered before the `CSS.style_tag` otherwise the `[%cx]` calls won't be added to the stylesheet, since they aren't being executed yet.
154
+
155
+
`CSS.style_tag` returns a `<style />` with all styles injected, and you can think of CSS's stylesheet as a global registry for styles. If we place `CSS.style_tag` in the `<head>` and your `App` in the `<body>`, when we are rendering the head (happens before) the global registry won't have the dynamic classNames until App is rendered, which happens later, when React renders the `<body />`.
152
156
153
-
To solve this, we recommend: render the React application first, and then inject the result as `dangerouslySetInnerHTML`.
157
+
To solve this, we recommend: render the React application first as a string, and then inject the result as `dangerouslySetInnerHTML` in the `<body />`. This way we ensure that the execution of the `App` happens before collecting all classNames.
154
158
155
159
```reason
156
-
/* `App` here is the entry component of your React application, while the `Document` component is only meant to run on the server. */
160
+
/* `App` here is the entry component of your React application with the interactivity from React, while the `Document` component is running on the server and is static. */
If you don't want to render the stylesheet directly, you can use `CSS.get_stylesheet` to obtain the `stylesheet` as a `string`. In this case, the hydration with the client won't be supported.
183
187
184
-
To make sure hydration works, you would need the following `<style/>` tag
188
+
To make sure hydration works, you would need the following `<style/>` tag:
0 commit comments