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

Svelte actions would obsolete dom ref example #173

Closed
brunnerh opened this issue Jul 21, 2023 · 3 comments
Closed

Svelte actions would obsolete dom ref example #173

brunnerh opened this issue Jul 21, 2023 · 3 comments

Comments

@brunnerh
Copy link
Contributor

One can get a reference with bind:this, but it is often not necessary because there are actions.

The "dom ref" example:

<script>
  import { onMount } from "svelte";

  let inputElement;

  onMount(() => {
    inputElement.focus();
  });
</script>

<input bind:this={inputElement} />

Could be replaced with just:

<script>
  const focus = node => node.focus();
</script>

<input use:focus />

Actions probably do not have an equivalent in most libraries, but the current example is just so unnecessarily clunky...

@matschik
Copy link
Owner

The goal in the snippet named "Dom ref" is not to show how to focus an input.
The goal here is to show how to make a dom ref compared to other frameworks.

Component Party is focused on clarity when comparing with other frameworks, not over-optimization.

@brunnerh
Copy link
Contributor Author

I am aware of all that, the problem I have with the current code is that it gives a false impression/is not representative of code one should write. I also did not have clear way of fixing that, which is why I opened the issue.

@matschik
Copy link
Owner

matschik commented Jul 21, 2023

It just shows how to do a dom ref. So the problem is solved.
We don't need to go further. When you are learning Svelte from React or Vue knowledge for example, your proposition would be very confusing to make a dom ref even if it's interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants