3

How to get all properties on current svelte file?

for example this Component1.svelte

<script>
  let x = '';
  let y = '';
  let z = '';

  onMount(function(){
    console.log( what? ); 
    // need to print x, y, and z which set by other code
    // that using/importing this file
    // without defining one by one, was there such property?
  });
</script>
<span>{x}</span>
<div>{y}</div>
<p>{z}</p>

Used by whatever.svelte

<script>
   import Foo from `./Component1.svelte`
</script>
<Foo x="1" y="abc">test</Foo>

1 Answer 1

5

You can use $$props for this, it will return all properties passed on to the component.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.