solid-js 2.0.0-beta.1 → 2.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHEATSHEET.md +640 -0
- package/README.md +42 -188
- package/dist/dev.cjs +446 -291
- package/dist/dev.js +426 -293
- package/dist/server.cjs +941 -345
- package/dist/server.js +897 -299
- package/dist/solid.cjs +438 -261
- package/dist/solid.js +418 -263
- package/package.json +67 -39
- package/types/client/component.d.ts +64 -19
- package/types/client/core.d.ts +110 -34
- package/types/client/flow.d.ts +176 -42
- package/types/client/hydration.d.ts +513 -37
- package/types/index.d.ts +8 -13
- package/types/server/component.d.ts +11 -11
- package/types/server/core.d.ts +19 -21
- package/types/server/flow.d.ts +76 -21
- package/types/server/hydration.d.ts +34 -9
- package/types/server/index.d.ts +6 -8
- package/types/server/shared.d.ts +10 -2
- package/types/server/signals.d.ts +80 -19
- package/types/types.d.ts +15 -0
- package/types-cjs/client/component.d.cts +120 -0
- package/types-cjs/client/core.d.cts +141 -0
- package/types-cjs/client/flow.d.cts +234 -0
- package/types-cjs/client/hydration.d.cts +568 -0
- package/types-cjs/index.d.cts +15 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/server/component.d.cts +67 -0
- package/types-cjs/server/core.d.cts +42 -0
- package/types-cjs/server/flow.d.cts +115 -0
- package/types-cjs/server/hydration.d.cts +63 -0
- package/types-cjs/server/index.d.cts +10 -0
- package/types-cjs/server/shared.d.cts +54 -0
- package/types-cjs/server/signals.d.cts +123 -0
- package/types-cjs/types.d.cts +15 -0
- package/jsx-runtime.d.ts +0 -1
- package/types/jsx.d.ts +0 -4129
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"description": "Reactive JavaScript library for building user interfaces. Compiles JSX to real DOM with fine-grained signal-based updates — no virtual DOM.",
|
|
4
|
+
"version": "2.0.0-beta.11",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/solidjs/solid"
|
|
10
|
+
"url": "git+https://github.com/solidjs/solid.git",
|
|
11
|
+
"directory": "packages/solid"
|
|
11
12
|
},
|
|
12
13
|
"main": "./dist/server.cjs",
|
|
13
14
|
"module": "./dist/server.js",
|
|
@@ -18,55 +19,82 @@
|
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
21
|
"types",
|
|
21
|
-
"
|
|
22
|
-
"package.json"
|
|
22
|
+
"types-cjs",
|
|
23
|
+
"package.json",
|
|
24
|
+
"CHEATSHEET.md"
|
|
23
25
|
],
|
|
24
26
|
"exports": {
|
|
25
27
|
".": {
|
|
26
28
|
"worker": {
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"default": "./dist/server.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./types-cjs/index.d.cts",
|
|
35
|
+
"default": "./dist/server.cjs"
|
|
36
|
+
}
|
|
30
37
|
},
|
|
31
38
|
"browser": {
|
|
32
39
|
"development": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./types/index.d.ts",
|
|
42
|
+
"default": "./dist/dev.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./types-cjs/index.d.cts",
|
|
46
|
+
"default": "./dist/dev.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"import": {
|
|
33
50
|
"types": "./types/index.d.ts",
|
|
34
|
-
"
|
|
35
|
-
"require": "./dist/dev.cjs"
|
|
51
|
+
"default": "./dist/solid.js"
|
|
36
52
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./types-cjs/index.d.cts",
|
|
55
|
+
"default": "./dist/solid.cjs"
|
|
56
|
+
}
|
|
40
57
|
},
|
|
41
58
|
"deno": {
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./types/index.d.ts",
|
|
61
|
+
"default": "./dist/server.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./types-cjs/index.d.cts",
|
|
65
|
+
"default": "./dist/server.cjs"
|
|
66
|
+
}
|
|
45
67
|
},
|
|
46
68
|
"node": {
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./types/index.d.ts",
|
|
71
|
+
"default": "./dist/server.js"
|
|
72
|
+
},
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./types-cjs/index.d.cts",
|
|
75
|
+
"default": "./dist/server.cjs"
|
|
76
|
+
}
|
|
50
77
|
},
|
|
51
78
|
"development": {
|
|
79
|
+
"import": {
|
|
80
|
+
"types": "./types/index.d.ts",
|
|
81
|
+
"default": "./dist/dev.js"
|
|
82
|
+
},
|
|
83
|
+
"require": {
|
|
84
|
+
"types": "./types-cjs/index.d.cts",
|
|
85
|
+
"default": "./dist/dev.cjs"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"import": {
|
|
52
89
|
"types": "./types/index.d.ts",
|
|
53
|
-
"
|
|
54
|
-
"require": "./dist/dev.cjs"
|
|
90
|
+
"default": "./dist/solid.js"
|
|
55
91
|
},
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
"require": {
|
|
93
|
+
"types": "./types-cjs/index.d.cts",
|
|
94
|
+
"default": "./dist/solid.cjs"
|
|
95
|
+
}
|
|
59
96
|
},
|
|
60
|
-
"./dist/*": "./dist/*",
|
|
61
97
|
"./types/*": "./types/*",
|
|
62
|
-
"./jsx-runtime": {
|
|
63
|
-
"types": "./types/jsx.d.ts",
|
|
64
|
-
"default": "./dist/solid.js"
|
|
65
|
-
},
|
|
66
|
-
"./jsx-dev-runtime": {
|
|
67
|
-
"types": "./types/jsx.d.ts",
|
|
68
|
-
"default": "./dist/solid.js"
|
|
69
|
-
},
|
|
70
98
|
"./package.json": "./package.json"
|
|
71
99
|
},
|
|
72
100
|
"keywords": [
|
|
@@ -79,7 +107,7 @@
|
|
|
79
107
|
"performance"
|
|
80
108
|
],
|
|
81
109
|
"dependencies": {
|
|
82
|
-
"@solidjs/signals": "^0.11
|
|
110
|
+
"@solidjs/signals": "^2.0.0-beta.11",
|
|
83
111
|
"csstype": "^3.1.0",
|
|
84
112
|
"seroval": "~1.5.0",
|
|
85
113
|
"seroval-plugins": "~1.5.0"
|
|
@@ -88,12 +116,12 @@
|
|
|
88
116
|
"build": "npm-run-all -nl build:*",
|
|
89
117
|
"build:clean": "rimraf dist/ coverage/",
|
|
90
118
|
"build:js": "rollup -c",
|
|
91
|
-
"types": "npm-run-all -nl types
|
|
92
|
-
"types:clean": "rimraf types/",
|
|
93
|
-
"types:
|
|
94
|
-
"types:
|
|
119
|
+
"types": "npm-run-all -nl types:clean types:src types:cjs",
|
|
120
|
+
"types:clean": "rimraf types/ types-cjs/",
|
|
121
|
+
"types:src": "tsc --project ./tsconfig.build.json",
|
|
122
|
+
"types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs",
|
|
95
123
|
"test": "vitest run",
|
|
96
124
|
"coverage": "vitest run --coverage",
|
|
97
|
-
"test-types": "tsc --project tsconfig.test.json"
|
|
125
|
+
"test-types": "tsc --project tsconfig.test.json && tsc --project tsconfig.no-dom.json"
|
|
98
126
|
}
|
|
99
127
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Element as SolidElement } from "../types.js";
|
|
2
2
|
/**
|
|
3
|
-
* A general `Component` has no implicit `children` prop.
|
|
4
|
-
*
|
|
3
|
+
* A general `Component` has no implicit `children` prop. If desired, specify
|
|
4
|
+
* one explicitly, e.g. `Component<{ name: string; children: Element }>`.
|
|
5
5
|
*/
|
|
6
|
-
export type Component<P extends Record<string, any> = {}> = (props: P) =>
|
|
6
|
+
export type Component<P extends Record<string, any> = {}> = (props: P) => SolidElement;
|
|
7
7
|
/**
|
|
8
8
|
* Extend props to forbid the `children` prop.
|
|
9
9
|
* Use this to prevent accidentally passing `children` to components that
|
|
@@ -19,16 +19,14 @@ export type VoidProps<P extends Record<string, any> = {}> = P & {
|
|
|
19
19
|
*/
|
|
20
20
|
export type VoidComponent<P extends Record<string, any> = {}> = Component<VoidProps<P>>;
|
|
21
21
|
/**
|
|
22
|
-
* Extend props to allow
|
|
23
|
-
* type in JSX, `JSX.Element` (which allows elements, arrays, strings, etc.).
|
|
22
|
+
* Extend props to allow optional Solid children.
|
|
24
23
|
* Use this for components that you want to accept children.
|
|
25
24
|
*/
|
|
26
25
|
export type ParentProps<P extends Record<string, any> = {}> = P & {
|
|
27
|
-
children?:
|
|
26
|
+
children?: SolidElement;
|
|
28
27
|
};
|
|
29
28
|
/**
|
|
30
|
-
* `ParentComponent` allows an optional `children` prop
|
|
31
|
-
* type in JSX, `JSX.Element` (which allows elements, arrays, strings, etc.).
|
|
29
|
+
* `ParentComponent` allows an optional `children` prop.
|
|
32
30
|
* Use this for components that you want to accept children.
|
|
33
31
|
*/
|
|
34
32
|
export type ParentComponent<P extends Record<string, any> = {}> = Component<ParentProps<P>>;
|
|
@@ -36,34 +34,63 @@ export type ParentComponent<P extends Record<string, any> = {}> = Component<Pare
|
|
|
36
34
|
* Extend props to require a `children` prop with the specified type.
|
|
37
35
|
* Use this for components where you need a specific child type,
|
|
38
36
|
* typically a function that receives specific argument types.
|
|
39
|
-
* Note that all JSX <Elements> are of the type `JSX.Element`.
|
|
40
37
|
*/
|
|
41
|
-
export type FlowProps<P extends Record<string, any> = {}, C =
|
|
38
|
+
export type FlowProps<P extends Record<string, any> = {}, C = SolidElement> = P & {
|
|
42
39
|
children: C;
|
|
43
40
|
};
|
|
44
41
|
/**
|
|
45
42
|
* `FlowComponent` requires a `children` prop with the specified type.
|
|
46
43
|
* Use this for components where you need a specific child type,
|
|
47
44
|
* typically a function that receives specific argument types.
|
|
48
|
-
* Note that all JSX <Elements> are of the type `JSX.Element`.
|
|
49
45
|
*/
|
|
50
|
-
export type FlowComponent<P extends Record<string, any> = {}, C =
|
|
51
|
-
export type ValidComponent =
|
|
46
|
+
export type FlowComponent<P extends Record<string, any> = {}, C = SolidElement> = Component<FlowProps<P, C>>;
|
|
47
|
+
export type ValidComponent = Component<any>;
|
|
52
48
|
/**
|
|
53
49
|
* Takes the props of the passed component and returns its type
|
|
54
50
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* ComponentProps<'div'> // JSX.HTMLAttributes<HTMLDivElement>
|
|
51
|
+
* Intrinsic element prop extraction is renderer-specific and lives in renderer
|
|
52
|
+
* packages such as `@solidjs/web`.
|
|
58
53
|
*/
|
|
59
|
-
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P :
|
|
54
|
+
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : never;
|
|
60
55
|
/**
|
|
61
56
|
* Type of `props.ref`, for use in `Component` or `props` typing.
|
|
62
57
|
*
|
|
63
58
|
* @example Component<{ref: Ref<Element>}>
|
|
64
59
|
*/
|
|
65
60
|
export type Ref<T> = T | ((val: T) => void);
|
|
66
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Invokes a component, wrapping the call in `untrack` so that reactive reads
|
|
63
|
+
* inside the component body don't subscribe the parent computation. Compiled
|
|
64
|
+
* JSX uses this internally; manual calls are rarely needed unless authoring a
|
|
65
|
+
* custom JSX factory or renderer.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createComponent<T extends Record<string, any>>(Comp: Component<T>, props: T): SolidElement;
|
|
68
|
+
/**
|
|
69
|
+
* Defines a code-split component. The returned component triggers its dynamic
|
|
70
|
+
* import on first render and suspends through any enclosing `<Loading>`
|
|
71
|
+
* boundary while the chunk is in flight. Call `.preload()` to start the
|
|
72
|
+
* import early (e.g. on hover).
|
|
73
|
+
*
|
|
74
|
+
* @param fn dynamic import returning the module's default export
|
|
75
|
+
* @param moduleUrl optional module URL used during hydration to look up
|
|
76
|
+
* preloaded chunks; usually injected by the bundler integration
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* const Profile = lazy(() => import("./Profile"));
|
|
81
|
+
*
|
|
82
|
+
* function App() {
|
|
83
|
+
* return (
|
|
84
|
+
* <Loading fallback={<Spinner />}>
|
|
85
|
+
* <Profile id="42" />
|
|
86
|
+
* </Loading>
|
|
87
|
+
* );
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* // Preload before the user clicks
|
|
91
|
+
* <button onMouseEnter={() => Profile.preload()}>Open profile</button>
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
67
94
|
export declare function lazy<T extends Component<any>>(fn: () => Promise<{
|
|
68
95
|
default: T;
|
|
69
96
|
}>, moduleUrl?: string): T & {
|
|
@@ -72,4 +99,22 @@ export declare function lazy<T extends Component<any>>(fn: () => Promise<{
|
|
|
72
99
|
}>;
|
|
73
100
|
moduleUrl?: string;
|
|
74
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* Returns a stable id string that matches between server-rendered and
|
|
104
|
+
* client-hydrated trees. Use it for `<label for>`, `aria-labelledby`, and
|
|
105
|
+
* other attributes that need consistent ids across SSR.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```tsx
|
|
109
|
+
* function Field(props: { label: string }) {
|
|
110
|
+
* const id = createUniqueId();
|
|
111
|
+
* return (
|
|
112
|
+
* <>
|
|
113
|
+
* <label for={id}>{props.label}</label>
|
|
114
|
+
* <input id={id} />
|
|
115
|
+
* </>
|
|
116
|
+
* );
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
75
120
|
export declare function createUniqueId(): string;
|
package/types/client/core.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import type { Accessor,
|
|
2
|
-
import type {
|
|
1
|
+
import type { Accessor, EffectOptions } from "@solidjs/signals";
|
|
2
|
+
import type { ArrayElement, Element as SolidElement } from "../types.js";
|
|
3
3
|
import { FlowComponent } from "./component.js";
|
|
4
4
|
export declare const IS_DEV: string | boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Brand symbol marking dev-built components for `solid-devtools` /
|
|
7
|
+
* AI-readiness instrumentation. Internal cross-package wiring.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
5
11
|
export declare const $DEVCOMP: unique symbol;
|
|
6
12
|
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
|
7
13
|
export type ContextProviderComponent<T> = FlowComponent<{
|
|
@@ -9,57 +15,127 @@ export type ContextProviderComponent<T> = FlowComponent<{
|
|
|
9
15
|
}>;
|
|
10
16
|
export interface Context<T> extends ContextProviderComponent<T> {
|
|
11
17
|
id: symbol;
|
|
12
|
-
defaultValue: T;
|
|
18
|
+
defaultValue: T | undefined;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
|
-
* Creates a Context
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* Creates a Context for sharing state with descendants of a Provider in the
|
|
22
|
+
* component tree.
|
|
23
|
+
*
|
|
24
|
+
* The returned `Context` is itself a provider component — pass it a `value`
|
|
25
|
+
* prop to scope a value to its children. Read it inside descendants with
|
|
26
|
+
* `useContext`.
|
|
27
|
+
*
|
|
28
|
+
* Two forms:
|
|
29
|
+
*
|
|
30
|
+
* - **`createContext<T>()`** (default-less, the canonical form). Reading via
|
|
31
|
+
* `useContext` outside an enclosing Provider throws `ContextNotFoundError`.
|
|
32
|
+
* Use this for everything that carries reactive state — signals, stores,
|
|
33
|
+
* `[state, actions]` tuples, services. The Provider is mandatory by
|
|
34
|
+
* construction; the throw makes a missing Provider a loud bug instead of a
|
|
35
|
+
* silent no-op. The annotation `<T>` is required because there is no value
|
|
36
|
+
* to infer from.
|
|
37
|
+
* - **`createContext<T>(defaultValue)`** (default form). Reserved for the
|
|
38
|
+
* narrow case of contexts whose value is a primitive with a meaningful
|
|
39
|
+
* static fallback (theme, locale, frozen config). Outside any Provider,
|
|
40
|
+
* `useContext` returns `defaultValue`.
|
|
41
|
+
*
|
|
42
|
+
* If you want truly app-wide state, **don't use Context** — a module-scope
|
|
43
|
+
* signal/store *is* a global. Context is for scoping state to a subtree;
|
|
44
|
+
* that's why a Provider is required.
|
|
45
|
+
*
|
|
46
|
+
* @param defaultValue optional default; only meaningful for primitive
|
|
47
|
+
* fallbacks. Omit for any context carrying reactive state.
|
|
48
|
+
* @param options `{ name }` for debugging in development
|
|
49
|
+
* @returns a context object that doubles as its own provider component
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* // Reactive payload — default-less, throws if no Provider.
|
|
54
|
+
* type TodosCtx = readonly [Store<Todo[]>, TodoActions];
|
|
55
|
+
* const TodosContext = createContext<TodosCtx>();
|
|
56
|
+
*
|
|
57
|
+
* function App() {
|
|
58
|
+
* return (
|
|
59
|
+
* <TodosContext value={createTodos()}>
|
|
60
|
+
* <TodoList />
|
|
61
|
+
* </TodosContext>
|
|
62
|
+
* );
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* function TodoList() {
|
|
66
|
+
* const [todos, { addTodo }] = useContext(TodosContext); // typed as TodosCtx
|
|
67
|
+
* // ...
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* // Primitive default — falls back to "light" outside a Provider.
|
|
74
|
+
* const ThemeContext = createContext<"light" | "dark">("light");
|
|
75
|
+
*
|
|
76
|
+
* function Button() {
|
|
77
|
+
* const theme = useContext(ThemeContext); // "light" | "dark"
|
|
78
|
+
* return <button class={theme}>Click</button>;
|
|
21
79
|
* }
|
|
22
|
-
* export function createContext<T>(
|
|
23
|
-
* defaultValue?: T,
|
|
24
|
-
* options?: { name?: string }
|
|
25
|
-
* ): Context<T | undefined>;
|
|
26
80
|
* ```
|
|
27
|
-
* @param defaultValue optional default to inject into context
|
|
28
|
-
* @param options allows to set a name in dev mode for debugging purposes
|
|
29
|
-
* @returns The context that contains the Provider Component and that can be used with `useContext`
|
|
30
81
|
*
|
|
31
82
|
* @description https://docs.solidjs.com/reference/component-apis/create-context
|
|
32
83
|
*/
|
|
33
|
-
export declare function createContext<T>(defaultValue?:
|
|
34
|
-
export declare function createContext<T>(defaultValue: T, options?: EffectOptions): Context<T>;
|
|
84
|
+
export declare function createContext<T>(defaultValue?: T, options?: EffectOptions): Context<T>;
|
|
35
85
|
/**
|
|
36
|
-
*
|
|
86
|
+
* Reads the current value of a context.
|
|
87
|
+
*
|
|
88
|
+
* - For `createContext<T>()` (default-less): returns the value from the
|
|
89
|
+
* nearest enclosing Provider, or throws `ContextNotFoundError` if none is
|
|
90
|
+
* mounted. Return type is `T` (no narrowing required).
|
|
91
|
+
* - For `createContext<T>(defaultValue)`: returns the value from the nearest
|
|
92
|
+
* enclosing Provider, or `defaultValue` if none is mounted.
|
|
37
93
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
94
|
+
* In Solid, `useContext` is the canonical way to read context. There is no
|
|
95
|
+
* need for a wrapper hook that throws on missing Provider — the default-less
|
|
96
|
+
* form already does that, and its return type is `T`.
|
|
97
|
+
*
|
|
98
|
+
* @param context a context returned from `createContext`
|
|
99
|
+
* @returns the value provided by the nearest enclosing Provider, or the
|
|
100
|
+
* default if one was supplied to `createContext`
|
|
101
|
+
* @throws `ContextNotFoundError` if no Provider is mounted and the context
|
|
102
|
+
* was created without a default
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* const TodosContext = createContext<TodosCtx>();
|
|
107
|
+
*
|
|
108
|
+
* function TodoList() {
|
|
109
|
+
* const [todos, { addTodo }] = useContext(TodosContext); // throws if no Provider
|
|
110
|
+
* // ...
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
40
113
|
*
|
|
41
114
|
* @description https://docs.solidjs.com/reference/component-apis/use-context
|
|
42
115
|
*/
|
|
43
116
|
export declare function useContext<T>(context: Context<T>): T;
|
|
44
|
-
export type
|
|
45
|
-
export type ResolvedChildren =
|
|
117
|
+
export type ResolvedElement = Exclude<SolidElement, ArrayElement>;
|
|
118
|
+
export type ResolvedChildren = ResolvedElement | ResolvedElement[];
|
|
46
119
|
export type ChildrenReturn = Accessor<ResolvedChildren> & {
|
|
47
|
-
toArray: () =>
|
|
120
|
+
toArray: () => ResolvedElement[];
|
|
48
121
|
};
|
|
49
122
|
/**
|
|
50
|
-
* Resolves
|
|
123
|
+
* Resolves a `children` accessor and exposes the result as an accessor with
|
|
124
|
+
* a `.toArray()` helper. Use this when a component needs to inspect or
|
|
125
|
+
* iterate over its children rather than just render them through.
|
|
51
126
|
*
|
|
52
127
|
* @param fn an accessor for the children
|
|
53
|
-
* @returns
|
|
128
|
+
* @returns an accessor of the resolved children, with `.toArray()` for iteration
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* function List(props: { children: Element }) {
|
|
133
|
+
* const items = children(() => props.children);
|
|
134
|
+
* return <ul>{items.toArray().map(item => <li>{item}</li>)}</ul>;
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
54
137
|
*
|
|
55
138
|
* @description https://docs.solidjs.com/reference/component-apis/children
|
|
56
139
|
*/
|
|
57
|
-
export declare function children(fn: Accessor<
|
|
140
|
+
export declare function children(fn: Accessor<SolidElement>): ChildrenReturn;
|
|
58
141
|
export declare function devComponent<P, V>(Comp: (props: P) => V, props: P): V;
|
|
59
|
-
interface SourceMapValue {
|
|
60
|
-
value: unknown;
|
|
61
|
-
name?: string;
|
|
62
|
-
graph?: Owner;
|
|
63
|
-
}
|
|
64
|
-
export declare function registerGraph(value: SourceMapValue): void;
|
|
65
|
-
export {};
|