You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/documentation/docs/99-legacy/04-legacy-$$props-and-$$res...

31 lines
928 B

---
title: $$props and $$restProps
---
In runes mode, getting an object containing all the props that were passed in is easy, using the [`$props`]($props) rune.
In legacy mode, we use `$$props` and `$$restProps`:
- `$$props` contains all the props that were passed in, including ones that are not individually declared with the `export` keyword
- `$$restProps` contains all the props that were passed in _except_ the ones that were individually declared
For example, a `<Button>` component might need to pass along all its props to its own `<button>` element, except the `variant` prop:
```svelte
<script>
export let variant;
</script>
<button {...$$restProps} class="variant-{variant} {$$props.class ?? ''}">
click me
</button>
<style>
.variant-danger {
background: red;
}
</style>
```
In Svelte 3/4 using `$$props` and `$$restProps` creates a modest performance penalty, so they should only be used when needed.