docs: clarify performance concerns around props and restProps (#9047)

* docs: clarify performance concerns around props and restProps

* Update documentation/docs/02-template-syntax/02-basic-markup.md
pull/9037/head
Ben McCann 3 years ago committed by GitHub
parent 01cbb661d0
commit d6abd0a604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -85,13 +85,13 @@ An element or component can have multiple spread attributes, interspersed with r
<Widget {...things} />
```
`$$props` references all props that are passed to a component, including ones that are not declared with `export`. It is not generally recommended, as it is difficult for Svelte to optimise. But it can be useful in rare cases – for example, when you don't know at compile time what props might be passed to a component.
`$$props` references all props that are passed to a component, including ones that are not declared with `export`. Using `$$props` will not perform as well as references to a specific prop because changes to any prop will cause Svelte to recheck all usages of `$$props`. But it can be useful in some cases – for example, when you don't know at compile time what props might be passed to a component.
```svelte
<Widget {...$$props} />
```
`$$restProps` contains only the props which are _not_ declared with `export`. It can be used to pass down other unknown attributes to an element in a component. It shares the same optimisation problems as `$$props`, and is likewise not recommended.
`$$restProps` contains only the props which are _not_ declared with `export`. It can be used to pass down other unknown attributes to an element in a component. It shares the same performance characteristics compared to specific property access as `$$props`.
```svelte
<input {...$$restProps} />

Loading…
Cancel
Save