Skip to content

Commit b56ca44

Browse files
committed
update tabs
1 parent dd580f9 commit b56ca44

File tree

18 files changed

+374
-514
lines changed

18 files changed

+374
-514
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@solid-primitives/marker": "^0.1.0",
2727
"@solid-primitives/media": "^2.2.9",
2828
"@solid-primitives/platform": "^0.2.0",
29+
"@solid-primitives/storage": "^4.3.1",
2930
"@solidjs/meta": "^0.29.4",
3031
"@solidjs/router": "^0.15.3",
3132
"@solidjs/start": "^1.1.1",

pnpm-lock.yaml

Lines changed: 13 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/concepts/context.mdx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ This offers a way to access state across an application without passing props th
2121
Context is created using the [`createContext`](/reference/component-apis/create-context) function.
2222
This function has a `Provider` property that wraps the component tree you want to provide context to.
2323

24-
<TabsCodeBlocks>
25-
<div id="/context/create.js">
26-
```jsx
24+
```jsx tab title="/context/create.js"
2725
import { createContext } from "solid-js";
2826

2927
const MyContext = createContext();
3028
```
31-
</div>
32-
<div id="/context/component.jsx">
33-
```jsx
29+
30+
```jsx tab title="/context/component.jsx"
3431
import { MyContext } from "./create";
3532

3633
export function Provider (props) {
@@ -41,8 +38,6 @@ export function Provider (props) {
4138
)
4239
};
4340
```
44-
</div>
45-
</TabsCodeBlocks>
4641

4742
## Providing context to children
4843

@@ -161,9 +156,7 @@ export function CounterProvider(props) {
161156
[Signals](/concepts/signals) offer a way to synchronize and manage data shared across your components using context.
162157
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.
163158
164-
<TabsCodeBlocks>
165-
<div id="App.jsx">
166-
```jsx
159+
```jsx tab title="App.jsx"
167160
import { CounterProvider } from "./Context";
168161
import { Child } from "./Child";
169162

@@ -176,9 +169,8 @@ export function App() {
176169
)
177170
}
178171
```
179-
</div>
180-
<div id="Context.jsx">
181-
```jsx
172+
173+
```jsx tab title="Context.jsx"
182174
import { createSignal, useContext } from "solid-js";
183175

184176
export function CounterProvider(props) {
@@ -204,9 +196,9 @@ export function CounterProvider(props) {
204196

205197
export function useCounter() { return useContext(CounterContext); }
206198
```
207-
</div>
208-
<div id="Child.jsx">
209-
```tsx title="/context/counter-component.tsx"
199+
200+
```tsx tab title="Child.jsx"
201+
// /context/counter-component.tsx
210202
import { useCounter } from "./Context";
211203

212204
export function Child(props) {
@@ -221,8 +213,6 @@ export function Child(props) {
221213
);
222214
};
223215
```
224-
</div>
225-
</TabsCodeBlocks>
226216
227217
This offers a way to manage state across your components without having to pass props through intermediate elements.
228218
@@ -262,12 +252,12 @@ Read more about default values in the [`createContext`](/reference/component-api
262252
:::
263253
264254
Because of this, if an initial value was not passed to `createContext`, the TS type signature of `useContext` will indicate that
265-
the value returned might be `undefined` (as mentioned above).
266-
This can be quite annoying when you want to use the context inside a component, and particularly when immediately destructuring the context.
255+
the value returned might be `undefined` (as mentioned above).
256+
This can be quite annoying when you want to use the context inside a component, and particularly when immediately destructuring the context.
267257
Additionally, if you use `useContext` and it returns `undefined` (which is often, but not always, the result of a bug), the error message thrown at runtime can be confusing.
268258
269-
The most common solution for it is to wrap all uses of `useContext` in a function that will explicitly throw a helpful error if the context is `undefined`.
270-
This also serves to narrow the type returned, so TS doesn't complain.
259+
The most common solution for it is to wrap all uses of `useContext` in a function that will explicitly throw a helpful error if the context is `undefined`.
260+
This also serves to narrow the type returned, so TS doesn't complain.
271261
As an example:
272262
273263
```ts title="/context/counter-component.tsx"
@@ -279,4 +269,3 @@ function useCounterContext() {
279269
return context
280270
}
281271
```
282-

src/routes/configuration/typescript.mdx

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -52,59 +52,16 @@ Transitioning from JavaScript to TypeScript in a Solid project offers the benefi
5252

5353
1. Install TypeScript into your project.
5454

55-
<TabsCodeBlocks>
56-
<div id="npm">
57-
```bash frame="none"
58-
npm i --save-dev typescript
55+
```package-install-dev
56+
typescript
5957
```
60-
</div>
61-
62-
<div id="yarn">
63-
```bash frame="none"
64-
yarn add --dev typescript
65-
```
66-
</div>
67-
68-
<div id="pnpm">
69-
```bash frame="none"
70-
pnpm add --save-dev typescript
71-
```
72-
</div>
73-
74-
<div id="bun">
75-
```bash frame="none"
76-
bun add --save-dev typescript
77-
```
78-
</div>
79-
</TabsCodeBlocks>
8058

8159
2. Run the following command to generate a `tsconfig.json` file.
8260

83-
<TabsCodeBlocks>
84-
<div id="npm">
85-
```bash frame="none"
86-
npx tsc --init
87-
```
88-
</div>
8961

90-
<div id="yarn">
91-
```bash frame="none"
92-
yarn dlx tsc --init
62+
```package-exec
63+
tsc --init
9364
```
94-
</div>
95-
96-
<div id="pnpm">
97-
```bash frame="none"
98-
pnpm tsc --init
99-
```
100-
</div>
101-
102-
<div id="bun">
103-
```bash frame="none"
104-
bunx tsc --init
105-
```
106-
</div>
107-
</TabsCodeBlocks>
10865

10966
3. Update the contents of the `tsconfig.json` to match Solid's configuration:
11067

@@ -421,9 +378,9 @@ function MyGenericComponent<T>(props: MyProps<T>): JSX.Element {
421378
```
422379

423380
:::info
424-
Each `Component` type has a corresponding `Props` type that defines the shape
425-
of its properties. These `Props` types also accept the same generic types as
426-
their associated `Component` types.
381+
Each `Component` type has a corresponding `Props` type that defines the shape
382+
of its properties. These `Props` types also accept the same generic types as
383+
their associated `Component` types.
427384
:::
428385

429386
### Event handling
@@ -523,13 +480,13 @@ return <div ref={divRef!}>...</div>
523480
In this case, using `divRef!` within the `ref` attribute signals to TypeScript that `divRef` will receive an assignment after this stage, which is more in line with how Solid works.
524481

525482
:::info
526-
While TypeScript does catch incorrect usage of refs that occur before their
527-
JSX block definition, it currently does not identify undefined variables
528-
within certain nested functions in Solid. Therefore, additional care is needed
529-
when using `ref`s in functions such as
530-
[`createMemo`](/reference/basic-reactivity/create-memo),
531-
[`createRenderEffect`](/reference/secondary-primitives/create-render-effect),
532-
and [`createComputed`](/reference/secondary-primitives/create-computed).
483+
While TypeScript does catch incorrect usage of refs that occur before their
484+
JSX block definition, it currently does not identify undefined variables
485+
within certain nested functions in Solid. Therefore, additional care is needed
486+
when using `ref`s in functions such as
487+
[`createMemo`](/reference/basic-reactivity/create-memo),
488+
[`createRenderEffect`](/reference/secondary-primitives/create-render-effect),
489+
and [`createComputed`](/reference/secondary-primitives/create-computed).
533490
:::
534491

535492
Finally, a riskier approach involves using the definite assignment assertion right at the point of variable initialization.
@@ -584,9 +541,9 @@ return <div>{user()?.name}</div>;
584541

585542
return (
586543
<div>
587-
<Show when={user()}>{(nonNullishUser) => <>
588-
{nonNullishUser().name}
589-
</>}</Show>
544+
<Show when={user()}>
545+
{(nonNullishUser) => <>{nonNullishUser().name}</>}
546+
</Show>
590547
</div>
591548
);
592549
```
@@ -709,7 +666,7 @@ const handler: JSX.EventHandlerWithOptions<HTMLDivElement, Event> = {
709666

710667
:::info
711668
**Note**:
712-
By default, using native events like `mousemove` with the `on` prefix — for example, `<div on:mousemove={e => {}} />` will trigger a TypeScript error.
669+
By default, using native events like `mousemove` with the `on` prefix — for example, `<div on:mousemove={e => {}} />` — will trigger a TypeScript error.
713670
This occurs because these native events are not part of Solid's custom event type definitions.
714671
To solve this, the `CustomEvents` interface can be extended to include events from the `HTMLElementEventMap`:
715672

0 commit comments

Comments
 (0)