Skip to content

Commit 4dfc9d1

Browse files
Formatting updates (#680)
Co-authored-by: Atila Fassina <[email protected]>
1 parent 7aec198 commit 4dfc9d1

File tree

9 files changed

+125
-123
lines changed

9 files changed

+125
-123
lines changed

src/routes/advanced-concepts/fine-grained-reactivity.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const [count, setCount] = createSignal(1);
4444

4545
console.log(count()); // prints "1"
4646

47-
setCount(0); // modifies the count value to 0
47+
setCount(0); // changes count to 0
4848

4949
console.log(count()); // prints "0"
5050
```

src/routes/concepts/context.mdx

Lines changed: 69 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Provider = (props) => (
5151

5252
However, if you need to access multiple values, they must be passed as an object literal, or using double curly braces (`{{ }}`):
5353

54-
```jsx
54+
```jsx {15-19}
5555
import { createContext, createSignal } from "solid-js";
5656

5757
const MyContext = createContext("default value");
@@ -83,7 +83,7 @@ export const Provider = (props) => {
8383
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.
8484
This utility takes in the context object and returns the value(s) passed to the `Provider`:
8585

86-
```jsx
86+
```jsx {10}
8787
import { createContext, useContext } from "solid-js";
8888

8989
const MyContext = createContext();
@@ -107,7 +107,7 @@ export const App = () => (
107107
When you are passing multiple values into the `Provider`, you can destructure the context object to access the values you need.
108108
This provides a readable way to access the values you need without having to access the entire context object:
109109

110-
```jsx
110+
```jsx {26}
111111
import { createContext, useContext, createSignal } from "solid-js";
112112

113113
const MyContext = createContext();
@@ -119,7 +119,6 @@ const Provider = (props) => {
119119
foo: "bar",
120120
obj: true,
121121
};
122-
const [signal, setSignal] = createSignal("example signal");
123122
return (
124123
<MyContext.Provider
125124
value={{
@@ -134,7 +133,7 @@ const Provider = (props) => {
134133
};
135134

136135
const Child = () => {
137-
const { stringVal, numberVal } = useContext(MyContext); // only access the values you need through destructuring
136+
const { stringVal, numberVal } = useContext(MyContext);
138137
return (
139138
<>
140139
<h1>{stringVal}</h1>
@@ -218,72 +217,71 @@ export function CounterProvider(props) {
218217
[Signals](/concepts/signals) offer a way to synchronize and manage data shared across your components using context.
219218
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.
220219

221-
<TabsCodeBlocks>
222-
<div id="App.jsx">
223-
```jsx
224-
import Counter from "./counter";
225-
import { CounterProvider } from "./Context";
226-
import { Child } from "./Child";
227-
228-
export function App() {
229-
return (
230-
<CounterProvider count={1}>
231-
<h1>Welcome to Counter App</h1>
232-
<Child />
233-
</CounterProvider>
234-
)
235-
}
236-
```
237-
</div>
238-
<div id="Context.jsx">
239-
```jsx
240-
import { createSignal, createContext, useContext } from "solid-js";
241-
242-
const CounterContext = createContext(); // create context
243-
244-
export function CounterProvider(props) {
245-
const [count, setCount] = createSignal(props.count || 0),
246-
counter = [
247-
count,
248-
{
249-
increment() {
250-
setCount(prev => prev + 1);
251-
},
252-
decrement() {
253-
setCount(prev => prev - 1);
254-
}
255-
}
256-
];
257-
258-
return (
259-
<CounterContext.Provider value={counter}>
260-
{props.children}
261-
</CounterContext.Provider>
262-
);
263-
}
264-
265-
export function useCounter() { return useContext(CounterContext); }
266-
```
267-
</div>
268-
<div id="Child.jsx">
269-
```jsx
270-
import { useCounter } from "./Context";
271-
272-
export function Child(props) {
273-
const [count, { increment, decrement }] = useCounter();
274-
275-
return (
276-
<>
277-
<div>{count()}</div>
278-
<button onClick={increment}>+</button>
279-
<button onClick={decrement}>-</button>
280-
</>
281-
);
282-
};
283-
```
284-
</div>
285-
286-
</TabsCodeBlocks>
220+
<TabsCodeBlocks>
221+
<div id="App.jsx">
222+
```jsx
223+
import Counter from "./counter";
224+
import { CounterProvider } from "./Context";
225+
import { Child } from "./Child";
226+
227+
export function App() {
228+
return (
229+
<CounterProvider count={1}>
230+
<h1>Welcome to Counter App</h1>
231+
<Child />
232+
</CounterProvider>
233+
)
234+
}
235+
```
236+
</div>
237+
<div id="Context.jsx">
238+
```jsx
239+
import { createSignal, createContext, useContext } from "solid-js";
240+
241+
const CounterContext = createContext(); // create context
242+
243+
export function CounterProvider(props) {
244+
const [count, setCount] = createSignal(props.count || 0),
245+
counter = [
246+
count,
247+
{
248+
increment() {
249+
setCount(prev => prev + 1);
250+
},
251+
decrement() {
252+
setCount(prev => prev - 1);
253+
}
254+
}
255+
];
256+
257+
return (
258+
<CounterContext.Provider value={counter}>
259+
{props.children}
260+
</CounterContext.Provider>
261+
);
262+
}
263+
264+
export function useCounter() { return useContext(CounterContext); }
265+
```
266+
</div>
267+
<div id="Child.jsx">
268+
```jsx
269+
import { useCounter } from "./Context";
270+
271+
export function Child(props) {
272+
const [count, { increment, decrement }] = useCounter();
273+
274+
return (
275+
<>
276+
<div>{count()}</div>
277+
<button onClick={increment}>+</button>
278+
<button onClick={decrement}>-</button>
279+
</>
280+
);
281+
};
282+
```
283+
</div>
284+
</TabsCodeBlocks>
287285

288286
This offers a way to manage state across your components without having to pass props through intermediate elements.
289287

src/routes/concepts/effects.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { createSignal, createEffect } from "solid-js";
5959
const [count, setCount] = createSignal(0);
6060

6161
createEffect(() => {
62-
console.log(count()); // Logs the current value of count whenever it changes
62+
console.log(count()); // Logs current value of count whenever it changes
6363
});
6464
```
6565

@@ -87,12 +87,11 @@ setCount(1); // Output: 1, "Hello"
8787
setMessage("World"); // Output: 1, "World"
8888
```
8989

90-
<Callout>
91-
When a signal updates, it notifies all of its subscribers sequentially but the
92-
*order can vary*. While effects are guaranteed to run when a signal updates,
93-
the execution might **not** be instantaneous. This means that the order of
94-
execution of effects is *not guaranteed* and should not be relied upon.
95-
</Callout>
90+
<Callout>
91+
When a signal updates, it notifies all of its subscribers sequentially but the *order can vary*.
92+
While effects are guaranteed to run when a signal updates, the execution might **not** be instantaneous.
93+
This means that the order of execution of effects is *not guaranteed* and should not be relied upon.
94+
</Callout>
9695

9796
### Nested effects
9897

src/routes/concepts/intro-to-reactivity.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ function Counter() {
182182

183183
return (
184184
<div>
185-
<span>Count: {count()}</span>{" "}
186-
{/* ✅ will update whenever `count()` changes. */}
185+
<span>Count: {count()}</span>{/* ✅ will update whenever `count()` changes. */}
187186
<button type="button" onClick={increment}>
188187
Increment
189188
</button>
@@ -216,10 +215,11 @@ const [double, setDouble] = createSignal(0);
216215
createEffect(() => {
217216
setDouble(count() * 2);
218217
});
219-
// 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`.
221218
```
222219

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+
223223
### Asynchronous reactivity
224224

225225
[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.

src/routes/concepts/refs.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Solid provides a ref system to access DOM elements directly inside the JSX templ
3838

3939
To use [`ref`](/reference/jsx-attributes/ref), you declare a variable and use it as the `ref` attribute:
4040

41-
```tsx
41+
```tsx {6}
4242
function Component() {
4343
let myElement;
4444

@@ -54,16 +54,17 @@ These assignments occur at _creation time_ prior to the element being added to t
5454
If access to an element is needed before it is added to the DOM, you can use the callback form of `ref`:
5555

5656
```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>
6162
```
6263

6364
<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.
6768

6869
```tsx
6970
let myElement!: HTMLDivElement;
@@ -158,6 +159,7 @@ A directive is essentially a function with a specific signature:
158159

159160
```typescript
160161
function directive(element: Element, accessor: () => any): void
162+
161163
```
162164

163165
- `element`: The DOM element that the directive is applied to.

src/routes/concepts/signals.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ function Counter() {
7171
}
7272
```
7373

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.
7676

7777
Both functions subscribe to the signals accessed within them, establishing a dependency relationship.
7878
Once this relationship is established, the function is notified whenever the signal changes.

src/routes/concepts/stores.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ const App = () => {
193193
```
194194

195195
<Callout>
196-
Separating the read and write capabilities of a store provides a valuable debugging advantage.
196+
Separating the read and write capabilities of a store provides a valuable debugging advantage.
197197

198-
This separation facilitates the tracking and control of the components that are accessing or changing the values.
198+
This separation facilitates the tracking and control of the components that are accessing or changing the values.
199199
</Callout>
200200

201201
## Path syntax flexibility
@@ -358,12 +358,12 @@ When new information needs to be merged into an existing store `reconcile` can b
358358
```jsx
359359
const { createStore, reconcile } from "solid-js/stores"
360360

361-
const [data, setData] = createStore({
362-
animals: ['cat', 'dog', 'bird', 'gorilla']
363-
})
361+
const [data, setData] = createStore({
362+
animals: ['cat', 'dog', 'bird', 'gorilla']
363+
})
364364

365-
const newData = getNewData() // eg. contains ['cat', 'dog', 'bird', 'gorilla', 'koala']
366-
setData('animals', reconcile(newData))
365+
const newData = getNewData() // eg. contains ['cat', 'dog', 'bird', 'gorilla', 'koala']
366+
setData('animals', reconcile(newData))
367367

368368
```
369369

src/routes/concepts/understanding-jsx.mdx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ This updates only the necessary parts of the DOM when changes occur in the under
4242
4343
Where HTML lets you have disconnected tags at the top level, JSX requires that a component to return a single root element.
4444
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.
4949
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>
5252
5353
JSX maintains the familiar nested, tree-like structure found in HTML.
5454
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
9292
9393
```jsx
9494
<button style={{
95-
color: 'red',
96-
font-size: '2rem',
97-
}}>
95+
color: 'red',
96+
font-size: '2rem',
97+
}}>
9898
Click me!
9999
</button>
100100
```
101-
102-
</Callout>
101+
</Callout>
103102
104103
### JSX properties (props)
105104
@@ -120,12 +119,11 @@ They connect the component with the data it requires, for seamless data flows an
120119
Props are also used to fill components with data that comes from resources, like [`createResource`](/reference/basic-reactivity/create-resource) calls.
121120
This results in components that react in real-time to data changes.
122121

123-
<Callout>
124-
Expressions, whether fixed or dynamic, get applied *in the order defined within the JSX*.
125-
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'`.
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 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'`.
128125

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>
130128
131129
For how to use props effectively in Solid, explore the [props page](/concepts/components/props).

0 commit comments

Comments
 (0)