question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Switch props from "export let" to "import let"

See original GitHub issue

Describe the solution you’d like Whilst going through the tutorial, I was confused by the same use of export let name for both receiving in props from parent, and passing value up to the parent through bind. It seems that receiving props in using “export let” doesn’t really have the right connotation.

Describe alternatives you’ve considered Consider changing the syntax for receiving props to be import let name. Then you would have a clear distinction between what comes in, and what goes out.

Contrived example.

form.svelte

<script>
  import Field from './field.svelte'
  let name;
</script>

<Field type='text' label='Name' bind:value={name} />

field.svelte

<script>
  import let type;
  import let label;
  export let value;
</script>

<p>
  <label>{label}</label>
  <input type={type} bind:value={value} />
</p>

How important is this feature to you? It’s not critical, but for the above example, it makes things very clear what comes in and out. If both variable declarations were export, which is currently required, it makes things a bit confusing and requires code comments to explain.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Rich-Harriscommented, Aug 23, 2019

I’m going to save everyone’s time and close this issue, because I don’t see any realistic prospect of this changing. This has been discussed before at considerable length, and export is the best option. It doesn’t perfectly match the semantics of export in JavaScript modules, but it’s the most appropriate verb since in both contexts ‘export’ means ‘exposing a contract to the outside world’, and any replacement would have its own issues.

1reaction
paganayecommented, Oct 11, 2020

Import is certainly not an option. One option that would not break (all) javascript would be to add a prop keyword.

<script>
  prop type;
  prop type;
  prop value;
</script>
<p>
  <label>{label}</label>
  <input type={type} bind:value={value} />
</p>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Modern JavaScript – Imports, Exports, Let, Const, and ...
When we declare a variable as const , we cannot re-define or re-declare another const variable with the same name in the same...
Read more >
Is there a reason to not import/export state in place of prop ...
Basically is there a reason that prop drilling exists rather than just exporting and importing state from component to component?
Read more >
React Top-Level API
React components let you split the UI into independent, reusable pieces, and think about each piece in isolation. React components can be defined...
Read more >
Integrating TypeScript with Svelte | CSS-Tricks
Let's change the val prop to be checked as a number, via export let val: number; . The whole component now looks like...
Read more >
Working with Svelte stores - Learn web development | MDN
import { writable } from 'svelte/store' export const alert ... stores.js' import { onDestroy } from 'svelte' let alertContent = '' const ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found