Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Update tutorial on component binding #6852

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions site/content/docs/02-template-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -1348,12 +1348,10 @@ bind:this={component_instance}

Components also support `bind:this`, allowing you to interact with component instances programmatically.

> Note that we can't do `{cart.empty}` since `cart` is `undefined` when the button is first rendered and throws an error.

```sv
<ShoppingCart bind:this={cart}/>

<button on:click={() => cart.empty()}>
<button on:click={cart.empty}>
Empty shopping cart
</button>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

<InputField bind:this={field}/>

<button on:click={() => field.focus()}>Focus field</button>
<button on:click={field.focus}>Focus field</button>
6 changes: 2 additions & 4 deletions site/content/tutorial/06-bindings/14-component-this/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Just as you can bind to DOM elements, you can bind to component instances themse
Now we can programmatically interact with this component using `field`.

```html
<button on:click="{() => field.focus()}">
<button on:click="{field.focus}">
Focus field
</button>
```

> Note that we can't do `{field.focus}` since field is undefined when the button is first rendered and throws an error.
```