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
Once the values are available to all the components in the context's component tree, they can be accessed using the [`useContext`](/reference/component-apis/use-context) utility.
84
84
This utility takes in the context object and returns the value(s) passed to the `Provider`:
@@ -218,72 +217,71 @@ export function CounterProvider(props) {
218
217
[Signals](/concepts/signals) offer a way to synchronize and manage data shared across your components using context.
219
218
You can pass a signal directly to the `value` prop of the `Provider` component, and any changes to the signal will be reflected in all components that consume the context.
// The `double` signal will always be updated after `count` due to synchronous reactivity.
220
-
// This ensures that `double` is always up-to-date with the latest value of `count`.
221
218
```
222
219
220
+
In this example, the `double` signal will always be updated after `count` due to synchronous reactivity.
221
+
This ensures that `double` is always up-to-date with the latest value of `count`.
222
+
223
223
### Asynchronous reactivity
224
224
225
225
[Asynchronous](https://developer.mozilla.org/en-US/docs/Glossary/Asynchronous) reactivity is when a system responds to changes in a delayed or non-linear fashion.
Copy file name to clipboardExpand all lines: src/routes/concepts/refs.mdx
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Solid provides a ref system to access DOM elements directly inside the JSX templ
38
38
39
39
To use [`ref`](/reference/jsx-attributes/ref), you declare a variable and use it as the `ref` attribute:
40
40
41
-
```tsx
41
+
```tsx {6}
42
42
function Component() {
43
43
let myElement;
44
44
@@ -54,16 +54,17 @@ These assignments occur at _creation time_ prior to the element being added to t
54
54
If access to an element is needed before it is added to the DOM, you can use the callback form of `ref`:
55
55
56
56
```jsx
57
-
<p ref={el=> {
58
-
// el is created but not yet added to the DOM
59
-
myElement = el
60
-
}}>My Element</p>
57
+
<p ref={(el) => {
58
+
myElement = el // el is created but not yet added to the DOM
59
+
}}>
60
+
My Element
61
+
</p>
61
62
```
62
63
63
64
<Callout>
64
-
In TypeScript, you must use a definitive assignment assertion.
65
-
Since Solid takes care of assigning the variable when the component is rendered, this signals to TypeScript that the variable will be assigned, even if it can't
66
-
confirm it.
65
+
In TypeScript, you must use a definitive assignment assertion.
66
+
Since Solid takes care of assigning the variable when the component is rendered, this signals to TypeScript that the variable will be assigned, even if it can't
67
+
confirm it.
67
68
68
69
```tsx
69
70
let myElement!:HTMLDivElement;
@@ -158,6 +159,7 @@ A directive is essentially a function with a specific signature:
158
159
159
160
```typescript
160
161
function directive(element:Element, accessor: () =>any):void
162
+
161
163
```
162
164
163
165
-`element`: The DOM element that the directive is applied to.
Copy file name to clipboardExpand all lines: src/routes/concepts/signals.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,8 +71,8 @@ function Counter() {
71
71
}
72
72
```
73
73
74
-
<Callout>
75
-
A tracking scope can be created by [`createEffect`](/reference/basic-reactivity/create-effect) or [`createMemo`](/reference/basic-reactivity/create-memo), which are other Solid primitives.
74
+
<Callout>
75
+
A tracking scope can be created by [`createEffect`](/reference/basic-reactivity/create-effect) or [`createMemo`](/reference/basic-reactivity/create-memo), which are other Solid primitives.
76
76
77
77
Both functions subscribe to the signals accessed within them, establishing a dependency relationship.
78
78
Once this relationship is established, the function is notified whenever the signal changes.
Copy file name to clipboardExpand all lines: src/routes/concepts/understanding-jsx.mdx
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,13 +42,13 @@ This updates only the necessary parts of the DOM when changes occur in the under
42
42
43
43
Where HTML lets you have disconnected tags at the top level, JSX requires that a component to return a single root element.
44
44
45
-
<Callout type="advanced">
46
-
When working with JSX, parts of your code are translated into structured HTML that is placed at the start of the file.
47
-
Static elements are processed differently from dynamic ones, which might change based on data or user actions.
48
-
For dynamic elements, special markers are added for better handling during rendering.
45
+
<Callout type="advanced">
46
+
When working with JSX, parts of your code are translated into structured HTML that is placed at the start of the file.
47
+
Static elements are processed differently from dynamic ones, which might change based on data or user actions.
48
+
For dynamic elements, special markers are added for better handling during rendering.
49
49
50
-
Having a single root creates a consistent and manageable hierarchy to optimize rendering and updates.
51
-
</Callout>
50
+
Having a single root creates a consistent and manageable hierarchy to optimize rendering and updates.
51
+
</Callout>
52
52
53
53
JSX maintains the familiar nested, tree-like structure found in HTML.
54
54
As a result, parent-child relationships between elements become easier to follow.
@@ -92,14 +92,13 @@ In JSX files, HTML attributes are used much like regular HTML, with a few key di
92
92
93
93
```jsx
94
94
<button style={{
95
-
color: 'red',
96
-
font-size: '2rem',
97
-
}}>
95
+
color: 'red',
96
+
font-size: '2rem',
97
+
}}>
98
98
Click me!
99
99
</button>
100
100
```
101
-
102
-
</Callout>
101
+
</Callout>
103
102
104
103
### JSX properties (props)
105
104
@@ -120,12 +119,11 @@ They connect the component with the data it requires, for seamless data flows an
120
119
Props are also used to fill components with data that comes from resources, like [`createResource`](/reference/basic-reactivity/create-resource) calls.
121
120
This results in components that react in real-time to data changes.
122
121
123
-
<Callout>
124
-
Expressions, whether fixed or dynamic, get applied *in the order defined within the JSX*.
125
-
This works for a wide range ofDOM elements, but will not work with elements that require attributes to be defined in a special order, such as input types with`type='range'`.
126
-
127
-
When order influences an element's behavior, users must define the expressions in the order that the element is expected.
122
+
<Callout>
123
+
Expressions, whether fixed or dynamic, get applied *in the order defined within the JSX*.
124
+
This works for a wide range ofDOM elements, but will not work with elements that require attributes to be defined in a special order, such as input types with`type='range'`.
128
125
129
-
</Callout>
126
+
When order influences an element's behavior, users must define the expressions in the order that the element is expected.
127
+
</Callout>
130
128
131
129
For how to use props effectively in Solid, explore the [props page](/concepts/components/props).
0 commit comments