Skip to content

Commit b94a00a

Browse files
authored
Fix code snippets and improve clarity in use-submissions.mdx
1 parent a54bca6 commit b94a00a

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

src/routes/solid-router/reference/data-apis/use-submissions.mdx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ It's important to note that it requires the form method to be **post** otherwise
1313

1414
In the example below, the `useSubmissions` helper is used to retain a list of all submission results to that action while also giving feedback on the pending state of the current in-flight submission.
1515

16-
```tsx title="component.tsx" {4,9-15, 18}
16+
```tsx title="component.tsx" {5,10-16, 19}
17+
import { For, Show } from "solid-js";
1718
import { useSubmissions } from "@solidjs/router";
1819

1920
function Component() {
@@ -47,7 +48,8 @@ As an optional second parameter, the `useSubmissions` helper can receive a filte
4748
The filter receives the submitted data as a parameter and should return a boolean value.
4849
The action below will only submit if the name is "solid".
4950

50-
```tsx title="component.tsx" {4-7}
51+
```tsx title="component.tsx" {5-8}
52+
import { For, Show } from "solid-js";
5153
import { useSubmissions } from "@solidjs/router";
5254

5355
function Component() {
@@ -80,9 +82,8 @@ When the form is submitted, the `submission` object will be updated with the new
8082
This allows you to provide feedback to the user that the action is in progress.
8183
Once the action is complete, the `pending` property will be set to `false` and the `result` property will be updated with final value.
8284

83-
```tsx tab title="TypeScript" {6,13-20}
84-
// component.tsx
85-
import { Show } from "solid-js";
85+
```tsx tab title="TypeScript" {5,12-17}
86+
import { For, Show } from "solid-js";
8687
import { useSubmissions } from "@solidjs/router";
8788

8889
function Component() {
@@ -93,8 +94,11 @@ function Component() {
9394
<ul>
9495
<For each={Array.from(submissions.entries())}>
9596
{([, data]) => (
96-
<Show when={data.input[0].entries().next()} keyed>
97-
{(input) => <li>Optimistic: {input().value}</li>}
97+
<Show when={data.input[0].entries().next()}>
98+
{(input) => {
99+
const name = (input().value as [string, string])[1];
100+
return <li>Optimistic: {name}</li>;
101+
}}
98102
</Show>
99103
)}
100104
</For>
@@ -106,9 +110,8 @@ function Component() {
106110
}
107111
```
108112

109-
```tsx tab title="JavaScript" {6,13-20}
110-
// component.jsx
111-
import { Show } from "solid-js";
113+
```tsx tab title="JavaScript" {5,12-17}
114+
import { For, Show } from "solid-js";
112115
import { useSubmissions } from "@solidjs/router";
113116

114117
function Component() {
@@ -119,8 +122,11 @@ function Component() {
119122
<ul>
120123
<For each={Array.from(submissions.entries())}>
121124
{([, data]) => (
122-
<Show when={data.input[0].entries().next()} keyed>
123-
{(input) => <li>Optimistic: {input().value[1]}</li>}
125+
<Show when={data.input[0].entries().next()}>
126+
{(input) => {
127+
const name = input().value[1];
128+
return <li>Optimistic: {name}</li>;
129+
}}
124130
</Show>
125131
)}
126132
</For>
@@ -140,7 +146,7 @@ This allows you to provide feedback to the user that the action has failed. Addi
140146
At this stage, you can also use the `retry()` method to attempt the action again or the `clear()` to wipe the filled data in the platform.
141147

142148
```tsx title="component.tsx" {12-18}
143-
import { Show } from "solid-js";
149+
import { For, Show } from "solid-js";
144150
import { useSubmissions } from "@solidjs/router";
145151

146152
function Component() {

0 commit comments

Comments
 (0)