solid-js 2.0.0-beta.8 → 2.0.0-beta.9

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.
@@ -9,34 +9,101 @@ export type ContextProviderComponent<T> = FlowComponent<{
9
9
  }>;
10
10
  export interface Context<T> extends ContextProviderComponent<T> {
11
11
  id: symbol;
12
- defaultValue: T;
12
+ defaultValue: T | undefined;
13
13
  }
14
14
  /**
15
- * Creates a Context to handle a state scoped for the children of a component
16
- * ```typescript
17
- * interface Context<T> {
18
- * id: symbol;
19
- * Provider: FlowComponent<{ value: T }>;
20
- * defaultValue: T;
15
+ * Creates a Context for sharing state with descendants of a Provider in the
16
+ * component tree.
17
+ *
18
+ * The returned `Context` is itself a provider component — pass it a `value`
19
+ * prop to scope a value to its children. Read it inside descendants with
20
+ * `useContext`.
21
+ *
22
+ * Two forms:
23
+ *
24
+ * - **`createContext<T>()`** (default-less, the canonical form). Reading via
25
+ * `useContext` outside an enclosing Provider throws `ContextNotFoundError`.
26
+ * Use this for everything that carries reactive state — signals, stores,
27
+ * `[state, actions]` tuples, services. The Provider is mandatory by
28
+ * construction; the throw makes a missing Provider a loud bug instead of a
29
+ * silent no-op. The annotation `<T>` is required because there is no value
30
+ * to infer from.
31
+ * - **`createContext<T>(defaultValue)`** (default form). Reserved for the
32
+ * narrow case of contexts whose value is a primitive with a meaningful
33
+ * static fallback (theme, locale, frozen config). Outside any Provider,
34
+ * `useContext` returns `defaultValue`.
35
+ *
36
+ * If you want truly app-wide state, **don't use Context** — a module-scope
37
+ * signal/store *is* a global. Context is for scoping state to a subtree;
38
+ * that's why a Provider is required.
39
+ *
40
+ * @param defaultValue optional default; only meaningful for primitive
41
+ * fallbacks. Omit for any context carrying reactive state.
42
+ * @param options `{ name }` for debugging in development
43
+ * @returns a context object that doubles as its own provider component
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * // Reactive payload — default-less, throws if no Provider.
48
+ * type TodosCtx = readonly [Store<Todo[]>, TodoActions];
49
+ * const TodosContext = createContext<TodosCtx>();
50
+ *
51
+ * function App() {
52
+ * return (
53
+ * <TodosContext value={createTodos()}>
54
+ * <TodoList />
55
+ * </TodosContext>
56
+ * );
57
+ * }
58
+ *
59
+ * function TodoList() {
60
+ * const [todos, { addTodo }] = useContext(TodosContext); // typed as TodosCtx
61
+ * // ...
62
+ * }
63
+ * ```
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * // Primitive default — falls back to "light" outside a Provider.
68
+ * const ThemeContext = createContext<"light" | "dark">("light");
69
+ *
70
+ * function Button() {
71
+ * const theme = useContext(ThemeContext); // "light" | "dark"
72
+ * return <button class={theme}>Click</button>;
21
73
  * }
22
- * export function createContext<T>(
23
- * defaultValue?: T,
24
- * options?: { name?: string }
25
- * ): Context<T | undefined>;
26
74
  * ```
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
75
  *
31
76
  * @description https://docs.solidjs.com/reference/component-apis/create-context
32
77
  */
33
- export declare function createContext<T>(defaultValue?: undefined, options?: EffectOptions): Context<T | undefined>;
34
- export declare function createContext<T>(defaultValue: T, options?: EffectOptions): Context<T>;
78
+ export declare function createContext<T>(defaultValue?: T, options?: EffectOptions): Context<T>;
35
79
  /**
36
- * Uses a context to receive a scoped state from a parent's Context.Provider
80
+ * Reads the current value of a context.
81
+ *
82
+ * - For `createContext<T>()` (default-less): returns the value from the
83
+ * nearest enclosing Provider, or throws `ContextNotFoundError` if none is
84
+ * mounted. Return type is `T` (no narrowing required).
85
+ * - For `createContext<T>(defaultValue)`: returns the value from the nearest
86
+ * enclosing Provider, or `defaultValue` if none is mounted.
37
87
  *
38
- * @param context Context object made by `createContext`
39
- * @returns the current or `defaultValue`, if present
88
+ * In Solid, `useContext` is the canonical way to read context. There is no
89
+ * need for a wrapper hook that throws on missing Provider — the default-less
90
+ * form already does that, and its return type is `T`.
91
+ *
92
+ * @param context a context returned from `createContext`
93
+ * @returns the value provided by the nearest enclosing Provider, or the
94
+ * default if one was supplied to `createContext`
95
+ * @throws `ContextNotFoundError` if no Provider is mounted and the context
96
+ * was created without a default
97
+ *
98
+ * @example
99
+ * ```tsx
100
+ * const TodosContext = createContext<TodosCtx>();
101
+ *
102
+ * function TodoList() {
103
+ * const [todos, { addTodo }] = useContext(TodosContext); // throws if no Provider
104
+ * // ...
105
+ * }
106
+ * ```
40
107
  *
41
108
  * @description https://docs.solidjs.com/reference/component-apis/use-context
42
109
  */
@@ -47,10 +114,20 @@ export type ChildrenReturn = Accessor<ResolvedChildren> & {
47
114
  toArray: () => ResolvedJSXElement[];
48
115
  };
49
116
  /**
50
- * Resolves child elements to help interact with children
117
+ * Resolves a `children` accessor and exposes the result as an accessor with
118
+ * a `.toArray()` helper. Use this when a component needs to inspect or
119
+ * iterate over its children rather than just render them through.
51
120
  *
52
121
  * @param fn an accessor for the children
53
- * @returns a accessor of the same children, but resolved
122
+ * @returns an accessor of the resolved children, with `.toArray()` for iteration
123
+ *
124
+ * @example
125
+ * ```tsx
126
+ * function List(props: { children: JSX.Element }) {
127
+ * const items = children(() => props.children);
128
+ * return <ul>{items.toArray().map(item => <li>{item}</li>)}</ul>;
129
+ * }
130
+ * ```
54
131
  *
55
132
  * @description https://docs.solidjs.com/reference/component-apis/children
56
133
  */
@@ -41,7 +41,21 @@ export declare function Repeat<T extends JSX.Element>(props: {
41
41
  children: ((index: number) => T) | T;
42
42
  }): JSX.Element;
43
43
  /**
44
- * Conditionally render its children or an optional fallback component
44
+ * Conditionally renders its children when `when` is truthy, otherwise renders
45
+ * the optional `fallback`.
46
+ *
47
+ * The function-child form receives an accessor for the narrowed value — call
48
+ * it to read. Without `keyed` (default), the child is preserved across
49
+ * truthy values; with `keyed`, the child remounts whenever the value's
50
+ * identity changes.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * <Show when={user()} fallback={<SignIn />}>
55
+ * {u => <Greeting name={u().name} />}
56
+ * </Show>
57
+ * ```
58
+ *
45
59
  * @description https://docs.solidjs.com/reference/components/show
46
60
  */
47
61
  export declare function Show<T, F extends ConditionalRenderCallback<T>>(props: {
@@ -74,12 +88,24 @@ export type MatchProps<T, F extends ConditionalRenderCallback<T> = ConditionalRe
74
88
  children: ConditionalRenderChildren<T, F>;
75
89
  };
76
90
  /**
77
- * Selects a content based on condition when inside a `<Switch>` control flow
78
- * ```typescript
79
- * <Match when={condition()}>
80
- * <Content/>
81
- * </Match>
91
+ * A branch inside a `<Switch>`. The first `<Match>` whose `when` is truthy
92
+ * wins; remaining matches are skipped.
93
+ *
94
+ * Like `<Show>`, `<Match>` supports a function child that receives an
95
+ * accessor for the narrowed value.
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * <Switch fallback={<NotFound />}>
100
+ * <Match when={user()}>
101
+ * {u => <Profile name={u().name} />}
102
+ * </Match>
103
+ * <Match when={loading()}>
104
+ * <Spinner />
105
+ * </Match>
106
+ * </Switch>
82
107
  * ```
108
+ *
83
109
  * @description https://docs.solidjs.com/reference/components/switch-and-match
84
110
  */
85
111
  export declare function Match<T, F extends ConditionalRenderCallback<T>>(props: MatchProps<T, F>): JSX.Element;
@@ -103,14 +129,40 @@ export declare function Errored(props: {
103
129
  children: JSX.Element;
104
130
  }): JSX.Element;
105
131
  /**
106
- * Tracks all resources inside a component and renders a fallback until they are all resolved
107
- * ```typescript
108
- * const AsyncComponent = lazy(() => import('./component'));
132
+ * Renders a `fallback` while pending async reads inside the subtree settle.
133
+ *
134
+ * Any computation (`createMemo`, `createSignal(fn)`, `createStore(fn)`,
135
+ * `lazy(...)`, etc.) that throws because data isn't ready is caught by the
136
+ * nearest enclosing `<Loading>`. The boundary swaps to its `fallback` until
137
+ * every pending read has resolved, then renders the children.
138
+ *
139
+ * The optional `on` prop scopes the boundary so it ignores transitions
140
+ * caused by writes to other reactive sources — those transitions stay on the
141
+ * previous content (with `isPending()` flipping during the transition).
142
+ *
143
+ * Scope `<Loading>` around the data-dependent slot, not the surrounding
144
+ * shell. Wrapping layout chrome (header, nav, footer) in the same boundary
145
+ * as the data means revalidation replaces the entire screen with the
146
+ * fallback; rendering chrome outside the boundary keeps it stable while
147
+ * only the affordance flips.
109
148
  *
110
- * <Loading fallback={<LoadingIndicator />}>
111
- * <AsyncComponent />
149
+ * @example
150
+ * ```tsx
151
+ * const Profile = lazy(() => import("./Profile"));
152
+ *
153
+ * <Loading fallback={<Spinner />}>
154
+ * <Profile />
112
155
  * </Loading>
113
156
  * ```
157
+ *
158
+ * @example
159
+ * ```tsx
160
+ * // Only show the fallback for transitions caused by writes to `route`.
161
+ * <Loading fallback={<Skeleton />} on={route}>
162
+ * <Page />
163
+ * </Loading>
164
+ * ```
165
+ *
114
166
  * @description https://docs.solidjs.com/reference/components/suspense
115
167
  */
116
168
  export declare function Loading(props: {