Skip to content
\n

I could do:

\n
<svelte:boundary>\n{@const field = 'dept' }\n{@const label = 'Departament' }\n{@const error = $modalForm.errors[field] }\n<div class=\"mb-4\">\n  <label for=\"f-{field}\" class=\"form-label mb-1\">{label}</label>\n  <select\n    id=\"f-{field}\"\n    class=\"form-select\"\n    bind:value={$modalForm[field]}\n    class:border-danger={!!error}\n  >\n    <option value=\"\">Please select</option>\n    {#each deptOptions as option (option.value)}\n      <option value={option.value}>{option.text}</option>\n    {/each}\n  </select>\n  {#if !!error}\n    <div class=\"invalid-feedback d-block\">{error}</div>\n  {/if}\n</div>\n</svelte:boundary>\n
\n

Which seems cleaner and less error prone. (It is not practical for me at this point to convert these form fields to components because there are too many small differences and things to take into account).

\n

Would you advise against it for some reason?

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

I would advise against it because boundaries are for error handling and working with async data.
\nEven if you do not use them for that, they cause some overhead and could be confusing to anyone reading the code.

\n

If anything, I would go with {#if true}, though that will also be unnecessary if #16490 gets implemented.

","upvoteCount":1,"url":"https://github.com/sveltejs/svelte/discussions/16705#discussioncomment-14297282"}}}
Discussion options

You must be logged in to vote

I would advise against it because boundaries are for error handling and working with async data.
Even if you do not use them for that, they cause some overhead and could be confusing to anyone reading the code.

If anything, I would go with {#if true}, though that will also be unnecessary if #16490 gets implemented.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by guillemc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants