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: old pages/concepts/understanding-jsx.mdx
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,15 +23,15 @@ This provides a concise and readable way to create and represent components.
23
23
24
24
Solid was designed to align closely with HTML standards.
25
25
26
-
```jsx
26
+
```tsx
27
27
const element = <h1>I'm JSX!!</h1>
28
28
```
29
29
30
30
It offers a distinct advantage, however: to copy/paste solutions from resources like Stack Overflow; and to allow direct usage of templates from design tools.
31
31
Solid sets itself apart by using JSX immediately as it returns [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction) elements.
32
32
This lets you use dynamic expressions within your HTML by allowing variables and functions to be references with the use of curly braces (`{ }`):
33
33
34
-
```jsx
34
+
```tsx
35
35
const Component = () => {
36
36
const animal = { breed: "cat", name: "Midnight" }
37
37
@@ -54,7 +54,7 @@ This updates only the necessary parts of the DOM when changes occur in the under
54
54
55
55
Where HTML lets you have disconnected tags at the top level, JSX requires that a component to return a single root element.
56
56
57
-
:::advanced
57
+
:::note
58
58
When working with JSX, parts of your code are translated into structured HTML that is placed at the start of the file.
59
59
Static elements are processed differently from dynamic ones, which might change based on data or user actions.
60
60
For dynamic elements, special markers are added for better handling during rendering.
@@ -71,7 +71,7 @@ Self-closing tags are a must in JSX.
71
71
Unlike in HTML, where elements like `<input>`, `<img>`, or `<br>` don't require explicit closure, JSX requires consistent self-closing tags.
72
72
This helps to avoid potential rendering issues.
73
73
74
-
```jsx
74
+
```tsx
75
75
<imgsrc="./image-here.png" />
76
76
```
77
77
@@ -93,23 +93,25 @@ In JSX files, HTML attributes are used much like regular HTML, with a few key di
93
93
(**Note:** When using ESLint, you will get a warning if you use lowercase.)
94
94
- In cases where you can dynamically specify a value, you can replace the `"` and `"` with curly braces (`{ }`):
95
95
96
-
```jsx
96
+
```tsx
97
97
<buttonclass="myClass"onClick={handleClick}>
98
98
Click me!
99
99
</button>
100
100
```
101
101
102
-
:::note
103
-
If you wish to pass objects in JSX, such as with inline styling, you will have to use double curly braces (`{{ }}`).
102
+
:::note
103
+
104
+
If you wish to pass objects in JSX, such as with inline styling, you will have to use double curly braces (`{{ }}`).
104
105
105
-
```jsx
106
+
```tsx
106
107
<buttonstyle={{
107
108
color: 'red',
108
109
font-size: '2rem',
109
110
}}>
110
111
Click me!
111
112
</button>
112
113
```
114
+
113
115
:::
114
116
115
117
### JSX properties (props)
@@ -132,10 +134,12 @@ They connect the component with the data it requires, for seamless data flows an
132
134
This results in components that react in real-time to data changes.
133
135
134
136
:::note
137
+
135
138
Expressions, whether fixed or dynamic, get applied *in the order defined within the JSX*.
136
139
This works for a wide range of DOM elements, but will not work with elements that require attributes to be defined in a special order, such as input types with `type='range'`.
137
140
138
141
When order influences an element's behavior, users must define the expressions in the order that the element is expected.
142
+
139
143
:::
140
144
141
145
For how to use props effectively in Solid, explore the [props page](/concepts/components/props).
0 commit comments