Skip to content

Commit

Permalink
docs: update solid docs (#819)
Browse files Browse the repository at this point in the history
* docs: setup solid guides config, add basic concepts to solid guides

* docs: update code formatting, add form validation to solid guides

* docs: add async initial values to solid guides

* docs: add linked fields to solid guides, change "basic usage" section title to h2
  • Loading branch information
TropicolX authored Jul 8, 2024
1 parent 48456a9 commit 04fda1c
Show file tree
Hide file tree
Showing 6 changed files with 976 additions and 50 deletions.
203 changes: 154 additions & 49 deletions docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
},
{
"label": "Guides",
"children": [
],
"children": [],
"frameworks": [
{
"label": "react",
Expand Down Expand Up @@ -165,9 +164,25 @@
{
"label": "solid",
"children": [
{
"label": "Basic Concepts",
"to": "framework/solid/guides/basic-concepts"
},
{
"label": "Form Validation",
"to": "framework/solid/guides/validation"
},
{
"label": "Async Initial Values",
"to": "framework/solid/guides/async-initial-values"
},
{
"label": "Arrays",
"to": "framework/solid/guides/arrays"
},
{
"label": "Linked Fields",
"to": "framework/solid/guides/linked-fields"
}
]
}
Expand All @@ -176,78 +191,168 @@
{
"label": "API Reference",
"children": [
{"label": "JavaScript Reference", "to": "reference/index"},
{"label": "Classes / FieldApi", "to": "reference/fieldapi"},
{"label": "Classes / FormApi", "to": "reference/formapi"},
{"label": "Functions / formOptions", "to": "reference/formoptions"},
{"label": "Functions / mergeForm", "to": "reference/mergeform"},
{"label": "Interfaces / FieldApiOptions", "to": "reference/fieldapioptions"},
{"label": "Interfaces / FieldOptions", "to": "reference/fieldoptions"},
{"label": "Interfaces / FieldValidators", "to": "reference/fieldvalidators"},
{"label": "Interfaces / FormOptions", "to": "reference/formoptions"},
{"label": "Interfaces / FormValidators", "to": "reference/formvalidators"},
{"label": "Types / DeepKeys", "to": "reference/deepkeys"},
{"label": "Types / DeepValue", "to": "reference/deepvalue"},
{"label": "Types / FieldInfo", "to": "reference/fieldinfo"},
{"label": "Types / FieldMeta", "to": "reference/fieldmeta"},
{"label": "Types / FieldState", "to": "reference/fieldstate"},
{"label": "Types / FormState", "to": "reference/formstate"},
{"label": "Types / Updater", "to": "reference/updater"},
{"label": "Types / UpdaterFn", "to": "reference/updaterfn"},
{"label": "Types / ValidationError", "to": "reference/validationerror"},
{"label": "Types / ValidationMeta", "to": "reference/validationmeta"}
{ "label": "JavaScript Reference", "to": "reference/index" },
{ "label": "Classes / FieldApi", "to": "reference/fieldapi" },
{ "label": "Classes / FormApi", "to": "reference/formapi" },
{ "label": "Functions / formOptions", "to": "reference/formoptions" },
{ "label": "Functions / mergeForm", "to": "reference/mergeform" },
{
"label": "Interfaces / FieldApiOptions",
"to": "reference/fieldapioptions"
},
{
"label": "Interfaces / FieldOptions",
"to": "reference/fieldoptions"
},
{
"label": "Interfaces / FieldValidators",
"to": "reference/fieldvalidators"
},
{ "label": "Interfaces / FormOptions", "to": "reference/formoptions" },
{
"label": "Interfaces / FormValidators",
"to": "reference/formvalidators"
},
{ "label": "Types / DeepKeys", "to": "reference/deepkeys" },
{ "label": "Types / DeepValue", "to": "reference/deepvalue" },
{ "label": "Types / FieldInfo", "to": "reference/fieldinfo" },
{ "label": "Types / FieldMeta", "to": "reference/fieldmeta" },
{ "label": "Types / FieldState", "to": "reference/fieldstate" },
{ "label": "Types / FormState", "to": "reference/formstate" },
{ "label": "Types / Updater", "to": "reference/updater" },
{ "label": "Types / UpdaterFn", "to": "reference/updaterfn" },
{
"label": "Types / ValidationError",
"to": "reference/validationerror"
},
{ "label": "Types / ValidationMeta", "to": "reference/validationmeta" }
],
"frameworks": [
{
"label": "react",
"children": [
{"label": "React Reference", "to": "framework/react/reference/index"},
{"label": "Functions / createServerValidate", "to": "framework/react/reference/createservervalidate"},
{"label": "Functions / Field", "to": "framework/react/reference/field"},
{"label": "Functions / useField", "to": "framework/react/reference/usefield"},
{"label": "Functions / useForm", "to": "framework/react/reference/useform"},
{"label": "Functions / useTransform", "to": "framework/react/reference/usetransform"},
{"label": "Types / FieldComponent", "to": "framework/react/reference/fieldcomponent"},
{"label": "Types / UseField", "to": "framework/react/reference/usefield"},
{"label": "Variables / initialFormState", "to": "framework/react/reference/initialformstate"}
{
"label": "React Reference",
"to": "framework/react/reference/index"
},
{
"label": "Functions / createServerValidate",
"to": "framework/react/reference/createservervalidate"
},
{
"label": "Functions / Field",
"to": "framework/react/reference/field"
},
{
"label": "Functions / useField",
"to": "framework/react/reference/usefield"
},
{
"label": "Functions / useForm",
"to": "framework/react/reference/useform"
},
{
"label": "Functions / useTransform",
"to": "framework/react/reference/usetransform"
},
{
"label": "Types / FieldComponent",
"to": "framework/react/reference/fieldcomponent"
},
{
"label": "Types / UseField",
"to": "framework/react/reference/usefield"
},
{
"label": "Variables / initialFormState",
"to": "framework/react/reference/initialformstate"
}
]
},
{
"label": "vue",
"children": [
{"label": "Vue Reference", "to": "framework/vue/reference/index"},
{"label": "Functions / Field", "to": "framework/vue/reference/field"},
{"label": "Functions / useField", "to": "framework/vue/reference/usefield"},
{"label": "Functions / useForm", "to": "framework/vue/reference/useform"},
{"label": "Types / FieldComponent", "to": "framework/vue/reference/fieldcomponent"},
{"label": "Types / UseField", "to": "framework/vue/reference/usefield"}
{ "label": "Vue Reference", "to": "framework/vue/reference/index" },
{
"label": "Functions / Field",
"to": "framework/vue/reference/field"
},
{
"label": "Functions / useField",
"to": "framework/vue/reference/usefield"
},
{
"label": "Functions / useForm",
"to": "framework/vue/reference/useform"
},
{
"label": "Types / FieldComponent",
"to": "framework/vue/reference/fieldcomponent"
},
{
"label": "Types / UseField",
"to": "framework/vue/reference/usefield"
}
]
},
{
"label": "solid",
"children": [
{"label": "Solid Reference", "to": "framework/solid/reference/index"},
{"label": "Functions / createField", "to": "framework/solid/reference/createfield"},
{"label": "Functions / createForm", "to": "framework/solid/reference/createform"},
{"label": "Functions / Field", "to": "framework/solid/reference/field"},
{"label": "Types / CreateField", "to": "framework/solid/reference/createfield"},
{"label": "Types / FieldComponent", "to": "framework/solid/reference/fieldcomponent"}
{
"label": "Solid Reference",
"to": "framework/solid/reference/index"
},
{
"label": "Functions / createField",
"to": "framework/solid/reference/createfield"
},
{
"label": "Functions / createForm",
"to": "framework/solid/reference/createform"
},
{
"label": "Functions / Field",
"to": "framework/solid/reference/field"
},
{
"label": "Types / CreateField",
"to": "framework/solid/reference/createfield"
},
{
"label": "Types / FieldComponent",
"to": "framework/solid/reference/fieldcomponent"
}
]
},
{
"label": "lit",
"children": [
{"label": "Lit Reference", "to": "framework/lit/reference/index"},
{"label": "Classes / TanStackFormController", "to": "framework/lit/reference/tanstackformcontroller"}
{ "label": "Lit Reference", "to": "framework/lit/reference/index" },
{
"label": "Classes / TanStackFormController",
"to": "framework/lit/reference/tanstackformcontroller"
}
]
},
{
"label": "angular",
"children": [
{"label": "Angular Reference", "to": "framework/angular/reference/index"},
{"label": "Classes / TanStackField", "to": "framework/angular/reference/tanstackfield"},
{"label": "Functions / injectForm", "to": "framework/angular/reference/injectform"},
{"label": "Functions / injectStore", "to": "framework/angular/reference/injectstore"}
{
"label": "Angular Reference",
"to": "framework/angular/reference/index"
},
{
"label": "Classes / TanStackField",
"to": "framework/angular/reference/tanstackfield"
},
{
"label": "Functions / injectForm",
"to": "framework/angular/reference/injectform"
},
{
"label": "Functions / injectStore",
"to": "framework/angular/reference/injectstore"
}
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/guides/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Arrays

TanStack Form supports arrays as values in a form, including sub-object values inside of an array.

# Basic Usage
## Basic Usage

To use an array, you can use `field.state.value` on an array value in conjunction
with [`Index` from `solid-js`](https://www.solidjs.com/tutorial/flow_index):
Expand Down
50 changes: 50 additions & 0 deletions docs/framework/solid/guides/async-initial-values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
id: async-initial-values
title: Async Initial Values
---

Let's say that you want to fetch some data from an API and use it as the initial value of a form.

While this problem sounds simple on the surface, there are hidden complexities you might not have thought of thus far.

For example, you might want to show a loading spinner while the data is being fetched, or you might want to handle errors gracefully.
Likewise, you could also find yourself looking for a way to cache the data so that you don't have to fetch it every time the form is rendered.

While we could implement many of these features from scratch, it would end up looking a lot like another project we maintain: [TanStack Query](https://tanstack.com/query).

As such, this guide shows you how you can mix-n-match TanStack Form with TanStack Query to achieve the desired behavior.

## Basic Usage

```tsx
import { createForm } from '@tanstack/solid-form';
import { createQuery } from '@tanstack/solid-query';

export default function App() {
const { data, isLoading } = createQuery(() => ({
queryKey: ['data'],
queryFn: async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
return { firstName: 'FirstName', lastName: 'LastName' };
},
}));

const form = createForm(() => ({
defaultValues: {
firstName: data?.firstName ?? '',
lastName: data?.lastName ?? '',
},
onSubmit: async ({ value }) => {
// Do something with form data
console.log(value);
},
}));

if (isLoading) return <p>Loading..</p>;

return null;
}

```

This will show a loading spinner until the data is fetched, and then it will render the form with the fetched data as the initial values.
Loading

0 comments on commit 04fda1c

Please sign in to comment.