-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TanStack/main
feat: add docs
- Loading branch information
Showing
193 changed files
with
13,120 additions
and
7,698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected].1 | ||
uses: actions/[email protected].2 | ||
- name: Setup Tools | ||
uses: tanstack/config/.github/setup@main | ||
- name: Fix formatting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
20.15.1 | ||
22.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ coverage: | |
status: | ||
project: | ||
default: | ||
target: 90% | ||
target: auto | ||
threshold: 1% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
id: listeners | ||
title: Side effects for event triggers | ||
--- | ||
|
||
For situations where you want to "affect" or "react" to triggers, there's the listener API. For example, if you, as the developer, want to reset a form field as a result of another field changing, you would use the listener API. | ||
|
||
Imagine the following user flow: | ||
|
||
- User selects a country from a drop-down. | ||
- User then selects a province from another drop-down. | ||
- User changes the selected country to a different one. | ||
|
||
In this example, when the user changes the country, the selected province needs to be reset as it's no longer valid. With the listener API, we can subscribe to the onChange event and dispatch a reset to the field "province" when the listener is fired. | ||
|
||
Events that can be "listened" to are: | ||
|
||
- onChange | ||
- onBlur | ||
- onMount | ||
- onSubmit | ||
|
||
```angular-ts | ||
@Component({ | ||
selector: 'app-root', | ||
standalone: true, | ||
imports: [TanStackField], | ||
template: ` | ||
<ng-container | ||
[tanstackField]="form" | ||
name="country" | ||
[listeners]="{ | ||
onChange: onCountryChange | ||
}" | ||
#country="field" | ||
></ng-container> | ||
<ng-container | ||
[tanstackField]="form" | ||
name="province" | ||
#province="field" | ||
></ng-container> | ||
`, | ||
}) | ||
export class AppComponent { | ||
form = injectForm({ | ||
defaultValues: { | ||
country: '', | ||
province: '', | ||
}, | ||
}) | ||
onCountryChange: FieldListenerFn<any, any, any, any, string> = ({ | ||
value, | ||
}) => { | ||
console.log(`Country changed to: ${value}, resetting province`) | ||
this.form.setFieldValue('province', '') | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.