Skip to content

Commit daa0112

Browse files
authored
docs(solid-form): update the example code of async initial values (#1442)
Update async-initial-values.md - Destructuring query breaks the reactivity. - Don't do early return in Solid component, because it only runs once.
1 parent e7b0dcf commit daa0112

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

docs/framework/solid/guides/async-initial-values.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ As such, this guide shows you how you can mix-n-match TanStack Form with TanStac
1919
```tsx
2020
import { createForm } from '@tanstack/solid-form'
2121
import { createQuery } from '@tanstack/solid-query'
22+
import { Show } from 'solid-js'
2223

2324
export default function App() {
24-
const { data, isLoading } = createQuery(() => ({
25+
const query = createQuery(() => ({
2526
queryKey: ['data'],
2627
queryFn: async () => {
2728
await new Promise((resolve) => setTimeout(resolve, 1000))
@@ -31,18 +32,20 @@ export default function App() {
3132

3233
const form = createForm(() => ({
3334
defaultValues: {
34-
firstName: data?.firstName ?? '',
35-
lastName: data?.lastName ?? '',
35+
firstName: query.data?.firstName ?? '',
36+
lastName: query.data?.lastName ?? '',
3637
},
3738
onSubmit: async ({ value }) => {
3839
// Do something with form data
3940
console.log(value)
4041
},
4142
}))
4243

43-
if (isLoading) return <p>Loading..</p>
44-
45-
return null
44+
return (
45+
<Show when={!query.isLoading} fallback={<p>Loading..</p>}>
46+
<></>
47+
</Show>
48+
)
4649
}
4750
```
4851

0 commit comments

Comments
 (0)